python 的 proxy 问题
HTTPS_PROXY 也应该填写 http://127.0.0.1:7890,因为 HTTPS_PROXY 中 HTTPS 代表的是 出口协议,而 http://127.0.0.1:7890 代表和 127.0.0.1:7890 服务器之间的 入口协议 是 HTTP。而之前一直采用的上述错误配置,则会因为旧版本的 python 的 pip 内含的 urllib3 不支持 HTTPS 的 入口协议
查看proxy 有没有问题
HTTPS_PROXY 也应该填写 http://127.0.0.1:7890,因为 HTTPS_PROXY 中 HTTPS 代表的是 出口协议,而 http://127.0.0.1:7890 代表和 127.0.0.1:7890 服务器之间的 入口协议 是 HTTP
pip 内置了的 requests 和 urllib3 包,而不依赖全局的 requests 和 urllib3 包
当 pip 版本高于 20.3 时,内置的 requests 包升级到了 v2.25.0,urllib3 包也升级到了
v1.26.2,也就是说开始支持 HTTPS 的 入口协议 了,参见 pypa/pip 20.3 (2020-11-30) NEWS.rst
而之前一直采用的上述错误配置,则会因为旧版本的 python 的 pip 内含的 urllib3 不支持 HTTPS 的 入口协议 ,自动转换成了 HTTP 的 入口协议 进行连接了
个人推荐可以根据自己常用的科学上网工具所支持的 入口协议 来修改 urllib 库源码逻辑(文件位置一般在 **/python3./urllib/request.py 或者 ***/anaconda3/Lib/urllib/request.py)
if '=' in proxyServer:
# Per-protocol settings
for p in proxyServer.split(';'):
protocol, address = p.split('=', 1)
# See if address has a type:// prefix
if not re.match('(?:[^/:]+)://', address):
address = '%s://%s' % (protocol, address)
proxies[protocol] = address
else:
# Use one setting for all protocols
proxies['http'] = 'http://%s' % proxyServer
proxies['https'] = 'http://%s' % proxyServer
proxies['ftp'] = 'http://%s' % proxyServer
或者简单的按照下面的方式进行修改(并不一定适用所有情况)
if '=' in proxyServer:
# Per-protocol settings
for p in proxyServer.split(';'):
protocol, address = p.split('=', 1)
# See if address has a type:// prefix
if not re.match('(?:[^/:]+)://', address):
address = '%s://%s' % (protocol, address)
proxies[protocol] = address
else:
# Use one setting for all protocols
proxies['http'] = proxyServer
proxies['https'] = proxyServer
proxies['ftp'] = proxyServer
参考资料: https://ywang-wnlo.github.io/posts/76f6af57/
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)