# 警告：在连接被 'ProxyError' 中断后重试（重试总数=0）：('无法连接到代理。', error('隧道连接失败：需要 407 代理身份验证'))

- **ID:** `pip/network-proxy-authentication-407`
- **领域:** pip
- **类别:** network_error
- **错误码:** `407`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

pip 位于需要身份验证的企业代理后面，但环境或 pip 配置中缺少或错误的代理凭据。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 24.2 | active | — | — |
| Python 3.12 | active | — | — |
| urllib3 2.2 | active | — | — |

## 解决方案

1. ```
   在环境变量中设置带凭据的代理：Windows 上使用 'set HTTP_PROXY=http://user:password@proxy.company.com:8080' 和 'set HTTPS_PROXY=http://user:password@proxy.company.com:8080'，Linux/Mac 上使用 export。
   ```
2. ```
   全局配置 pip 的代理：'pip config set global.proxy http://user:password@proxy.company.com:8080'
   ```
3. ```
   使用代理身份验证助手如 'cntlm' 处理 NTLM 认证，并将 HTTP_PROXY 设置为 localhost:3128。
   ```

## 无效尝试

- **** — Setting HTTP_PROXY and HTTPS_PROXY without credentials still fails with 407; authentication is required. (95% 失败率)
- **** — Disabling proxy detection with '--proxy ""' may work only if the machine has direct internet access, but often fails in corporate networks. (70% 失败率)
- **** — Using 'pip install --trusted-host pypi.org' bypasses SSL checks but does not solve proxy authentication. (98% 失败率)
