【PYTHON】内网环境中,如何通过内网代理自动下载模型
背景
在内网环境跑python代码时,会涉及到下载模型,由于内容的原因,老是会报错urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='bj.bcebos.com', port=443): Max retries exceeded with url
解决办法
增加这两行代码os.environ["HTTP_PROXY"] = "http://xxxx:[email protected]:8080" os.environ["HTTPS_PROXY"] = "http://xxxx:[email protected]:8080"
import os import requests proxies ={"http":"http://xxxx:[email protected]:8080","https":"http://xxxx:[email protected]:8080"}try:# 测试能否连接模型服务器 response = requests.get("https://bj.bcebos.com", proxies=proxies, timeout=3000)print("代理连接成功,状态码:", response.status_code)except Exception as e:print("代理连接失败:", e) os.environ["HTTP_PROXY"]="http://xxxx:[email protected]:8080" os.environ["HTTPS_PROXY"]="http://xxxx:[email protected]:8080"from paddlenlp import Taskflow corrector = Taskflow("text_correction",timeout=3000)print(corrector("今天天气真很好"))