# aiohttp 客户端连接器 SSL 错误：证书验证失败

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

## 根因

远程服务器的 SSL 证书无效、已过期或不受系统 CA 包信任。

## 版本兼容性

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

## 解决方案

1. **Update system CA certificates** (80% 成功率)
   ```
   pip install certifi
# or update OS CA bundle
   ```
2. **Provide a custom SSL context with trusted certificates** (90% 成功率)
   ```
   import ssl
ssl_context = ssl.create_default_context(cafile='/path/to/cert.pem')
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=ssl_context)) as session:
   ```

## 无效尝试

- **Disabling SSL verification entirely with ssl=False** — This bypasses security and may lead to man-in-the-middle attacks; also not recommended for production. (30% 失败率)
- **Using a custom SSL context without proper certificates** — If the custom context is not configured correctly, the error persists. (60% 失败率)
