# requests.exceptions.ConnectionError: HTTPConnectionPool(host='proxy.example.com', port=8080): 超过最大重试次数 (由ProxyError('无法连接到代理。', OSError('隧道连接失败：407 代理身份验证必需'))引起)

- **ID:** `python/requests-connectionerror-proxy-authentication`
- **领域:** python
- **类别:** auth_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

代理需要身份验证凭据，但未提供。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Include username and password in the proxy URL** (95% 成功率)
   ```
   proxies = {'http': 'http://user:password@proxy.example.com:8080'}
requests.get('http://target.com', proxies=proxies)
   ```
2. **Use the requests.auth.HTTPProxyAuth class** (90% 成功率)
   ```
   from requests.auth import HTTPProxyAuth
auth = HTTPProxyAuth('user', 'password')
requests.get('http://target.com', proxies={'http': 'http://proxy.example.com:8080'}, auth=auth)
   ```

## 无效尝试

- **Setting the proxy URL without credentials** — The proxy server explicitly rejects connections without authentication. (95% 失败率)
- **Using an environment variable HTTP_PROXY without authentication** — Environment variables also need credentials if the proxy requires them. (90% 失败率)
