警告:在连接被 'ProxyError' 中断后重试(重试总数=0):('无法连接到代理。', error('隧道连接失败:需要 407 代理身份验证'))
WARNING: Retrying (Retry(total=0)) after connection broken by 'ProxyError': ('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required'))
ID: pip/network-proxy-authentication-407
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pip 24.2 | active | — | — | — |
| Python 3.12 | active | — | — | — |
| urllib3 2.2 | active | — | — | — |
根因分析
pip 位于需要身份验证的企业代理后面,但环境或 pip 配置中缺少或错误的代理凭据。
English
pip is behind a corporate proxy that requires authentication, but the proxy credentials are missing or incorrect in the environment or pip configuration.
官方文档
https://pip.pypa.io/en/stable/topics/configuration/#environment-variables解决方案
-
在环境变量中设置带凭据的代理:Windows 上使用 'set HTTP_PROXY=http://user:[email protected]:8080' 和 'set HTTPS_PROXY=http://user:[email protected]:8080',Linux/Mac 上使用 export。
-
全局配置 pip 的代理:'pip config set global.proxy http://user:[email protected]:8080'
-
使用代理身份验证助手如 'cntlm' 处理 NTLM 认证,并将 HTTP_PROXY 设置为 localhost:3128。
无效尝试
常见但无效的做法:
-
95% 失败
Setting HTTP_PROXY and HTTPS_PROXY without credentials still fails with 407; authentication is required.
-
70% 失败
Disabling proxy detection with '--proxy ""' may work only if the machine has direct internet access, but often fails in corporate networks.
-
98% 失败
Using 'pip install --trusted-host pypi.org' bypasses SSL checks but does not solve proxy authentication.