couldn’t connect to server_用另一种方式解决WARNING: Retrying (Retry(total=4, connect

这篇博客详细记录了作者在Linux系统中遇到的pip连接服务器问题,即便设置了代理仍无法在非base虚拟环境中正常下载包。文章通过错误说明和尝试的解决办法,最终提出了一种有效方案——通过export重新设置http和https代理,解决了无法下载特定包如pytorch和tensorflow的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

完整报错信息如下:

(open-mmlab) hench@hench-Precision-T3610:~$ pip install numpy
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)'))': /simple/numpy/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)'))': /simple/numpy/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1074: The handshake operation timed out'))': /simple/numpy/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)'))': /simple/numpy/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)'))': /simple/numpy/
Could not fetch URL https://pypi.org/simple/numpy/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/numpy/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)'))) - skipping
ERROR: Could not find a version that satisfies the requirement numpy
ERROR: No matching distribution found for numpy
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)'))) - skipping
(open-mmlab) hench@hench-Precision-T3610:~$ 

2021.1.18 更新:类似的连接错误也会发生在conda上

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/linux-64/current_repodata.json>
Elapsed: -

1 情况说明

  1. 我的Linux电脑是用代理proxy进行连接的。在ubuntu的设置-网络 设置过代理,也用代理设置代码给环境变量设置过代理。

这是我export出来的环境变量。

declare -x http_proxy="http://henchli:****@www-proxy.waseda.jp:8080/"
declare -x https_proxy="https://henchli:****@www-proxy.waseda.jp:8080/"

2. 在base环境中可以用pip下载包。

3d6886115145a40aed3a0ce84ac48454.png

2 错误说明

  1. 无法在非base由自己创建的虚拟环境中使用pip下载包。
  2. 把whl文件下载到本地然后用pip本地安装也是不行的。

675f88642a2df20aa3a44a20709af085.png

3 解决方法

关于这个问题,网上主要有两种解决思路。我先说不能解决我问题的第一种方法。

1. 各种花式--trusted-host(✘)

我第一次部分解决这个问题就是用了这个网页的方法,用的是douban的镜像。

但是这个方法只能下部分常见的包,比如numpy,scipy之类的。

如果douban没有收录这个包,比如pytorch和tensorflow,那就很麻烦了,比如要自己创建pip.conf然后写入--trusted-host,不同的网页还得改。

因此,我认为这些方法都不能从根本上解决问题。

2. 用export重新设置一次http代理[1] (✔)

export http_proxy="http://www-proxy.waseda.jp:8080"
export https_proxy="http://www-proxy.waseda.jp:8080"
# export http_proxy="http://<proxy.server>:<port>"

2021.1.13更新:碰到好几次过只改了http_proxy还是不行,然后把https_proxy也改了问题就解决了。

ca158df15a6fd4bffaef2e2f16f77476.png

参考

  1. ^https://stackoverflow.com/questions/19080352/how-to-get-pip-to-work-behind-a-proxy-server
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值