# aiohttp 客户端异常：连接证书错误

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

## 根因

目标服务器的 SSL 证书验证失败，通常是由于自签名证书或过期的 CA 链。

## 版本兼容性

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

## 解决方案

1. **Use a custom SSL context with verification** (90% 成功率)
   ```
   import ssl; ssl_ctx = ssl.create_default_context(); ssl_ctx.load_verify_locations('ca.pem')
connector = aiohttp.TCPConnector(ssl=ssl_ctx)
async with aiohttp.ClientSession(connector=connector) as session: ...
   ```
2. **Temporarily disable SSL verification for testing (not for production)** (70% 成功率)
   ```
   connector = aiohttp.TCPConnector(ssl=False)
async with aiohttp.ClientSession(connector=connector) as session: ...
   ```

## 无效尝试

- **Disabling SSL verification entirely with connector=False** — This reduces security and may cause warnings; not recommended for production. (40% 失败率)
- **Ignoring the error and retrying without changes** — The same error will recur because the certificate issue is not addressed. (90% 失败率)
