Python警告:正在重试(Retry(total=4,connect=None,read=None,redirect=None,status=None))

10
我正在尝试运行pip install --upgrade pip命令,但一直出现以下错误:
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnection
Error('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000026F50B448C8>: Failed to establish a new connection: [WinError 10061] No connection could be made
 because the target machine actively refused it'))': /simple/pytest/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnection
Error('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000026F50B59148>: Failed to establish a new connection: [WinError 10061] No connection could be made
 because the target machine actively refused it'))': /simple/pytest/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnection
Error('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000026F50B596C8>: Failed to establish a new connection: [WinError 10061] No connection could be made
 because the target machine actively refused it'))': /simple/pytest/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnection
Error('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000026F50B595C8>: Failed to establish a new connection: [WinError 10061] No connection could be made
 because the target machine actively refused it'))': /simple/pytest/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnection
Error('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000026F50B5F2C8>: Failed to establish a new connection: [WinError 10061] No connection could be made
 because the target machine actively refused it'))': /simple/pytest/
ERROR: Could not find a version that satisfies the requirement pytest
ERROR: No matching distribution found for pytest

此外,由于出现了这个错误,我无法安装任何新软件包。
我尝试重新安装Pycharm,但没有成功。
我尝试了一些其他在线建议的解决方案,但仍然无法解决问题。
我知道这与代理有关,但我不熟悉它。有人能帮忙吗?


3
错误信息已经非常明确地指出了问题的原因:您的代理服务器无法连接,或者您的代理配置存在问题。由于我们无法访问这两个内容,因此无法对此进行故障排除。 - tripleee
@tripleee,你有什么建议吗?根据你的说法,我的代理服务器已经失效了,我该如何“重新激活”它? - Omri
2
先向我们展示它的配置。如果这是公司或ISP的代理,您可能需要联系当地的IT支持。 - tripleee
这只是一个简短的评论,我在 VSCode 的 .devcontainer 中尝试 pip 安装时遇到了许多 NewConnectionError。原来是因为我分配给镜像的空间用完了,容器上的网络被禁用了。虽然不太直观,但在删除一些不必要的镜像后,它开始正常工作了。 - Andrew Wei
10个回答

10

尝试在构建命令后添加--network=host
例如:docker build -t cointainer_name . --network=host

If you use the host network mode for a container, that container’s network stack is not isolated from the 
Docker host (the container shares the host’s networking namespace), and the container does not 
get its own IP-address allocated. 
For instance, if you run a container which binds to port 80 and you use host 
networking, the container’s application is available on port 80 on the host’s IP address.

点击这里了解更多信息。


4

TL;DR, 这对Windows有效。

  1. Windows + I (打开设置).
  2. 选择 网络和Internet
  3. 选择 代理
  4. 检查 手动设置代理 是否处于关闭状态

---在这里都已经开始工作了---

  1. 注意: 我的 自动检测设置 切换为 对我没有影响(所有内容仍然像第4步一样工作)。

前言

我也遇到了同样的错误。 无法通过 pippipenv、anaconda或PyCharm 安装库。 然后我检查了 代理 设置(Windows 11 操作系统),发现我定义了一些手动设置代理。当我禁用它时,问题得到了解决。

问题非常突然:我做了一些 Python 工作,进行了一些安装(可能是使用 pipenv 安装的某些 python 模块,例如 notebook 或 jupyter-lab,还有 cygwin 工具等),然后安装/更新 python 模块崩溃了。也许某些安装改变了代理参数?我不知道。
重新安装 Python 也没能解决问题。

错误示例

例如,当安装/更新 anaconda 时出现错误如下:

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

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.

'https://repo.anaconda.com/pkgs/main/win-64'

安装/更新Pip时出现的错误看起来像这样:
pip install --upgrade pip

>>>
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', FileNotFoundError(2, 'No such file or directory'))': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', FileNotFoundError(2, 'No such file or directory'))': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', FileNotFoundError(2, 'No such file or directory'))': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', FileNotFoundError(2, 'No such file or directory'))': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', FileNotFoundError(2, 'No such file or directory'))': /simple/pip/

2

首先,重新安装所有的Python。 其次,在安装了Python之后,我找到了主机文件,并取消注释了主机部分。 通常情况下,Windows中的路径位于C:\Windows\System32\drivers\etc。

取消注释此部分:

本地主机名解析由DNS自身处理。

127.0.0.1       localhost
::1             localhost

希望这有所帮助!干杯!


1

我的环境

  • python3.8
  • windows10 + WSL
  • pip 21.0.4

我的步骤

  1. conda create -n py38 python=3.8
  2. pip install pandas

然后我遇到了这个错误 "Warning, retry ..."

如何解决问题

只需重新启动我的机器。


你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心找到有关如何编写良好答案的更多信息。 - Community

0
如果您在公司网络或VPN内,您可能可以访问这些软件包。断开与这些网络的连接,并连接到普通网络甚至手机热点,应该可以解决这个问题。

0
首先,进入“设置 => 网络和代理 => 代理”并将手动代理设置关闭。然后确保您的互联网连接正常,并且未连接到任何VPN。

0
winget install -id Microsoft.Powershell --source winget
winget install -id Microsoft.Powershell.Preview --source winget 

在PowerShell中输入上述命令,然后关闭Pycharm环境,再重新启动。这对我来说可以安装pip。


0
我的.bash_profile文件中有以下内容:
export SSLKEYLOGFILE=/Users/X/sslkeylog.log

移除SSLKEYLOGFILE的定义解决了问题。似乎Python 3.8+添加了对SSL密钥记录的支持,但它会导致一些问题。

-1
如果在Windows上安装了pip并且使用Python 3.10遇到以下错误:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', PermissionError(13, 'Permission denied'))': /simple/pip/

尝试更新Windows(操作系统)环境变量。关闭您的Windows用户会话,然后重新进入。这对我有效。

-1

请确保您未连接到 VPN 连接


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接