# aiohttp 客户端 HTTP 代理错误：需要代理认证

- **ID:** `python/aiohttp-client-connector-http-error`
- **领域:** python
- **类别:** auth_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

代理服务器需要认证，但未提供认证信息或凭据无效。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.10 | active | — | — |
| 3.11 | active | — | — |

## 解决方案

1. **Use aiohttp.BasicAuth for proxy authentication** (90% 成功率)
   ```
   proxy_auth = aiohttp.BasicAuth('username', 'password')
async with session.get(url, proxy='http://proxy.example.com:8080', proxy_auth=proxy_auth) as resp:
   ```
2. **Set proxy credentials in the URL** (85% 成功率)
   ```
   async with session.get(url, proxy='http://user:pass@proxy.example.com:8080') as resp:
   ```

## 无效尝试

- **Providing empty username and password** — Most proxies reject empty credentials, causing the same error. (60% 失败率)
- **Using HTTP Basic Auth headers manually without proper encoding** — Incorrect encoding or missing headers may still result in 407. (50% 失败率)
