# aiohttp.client_exceptions.ClientConnectorError: 无法连接到主机 api.example.com:443 ssl:default [连接调用失败]

- **ID:** `python/aiohttp-cannot-connect-to-host`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

对目标主机的 DNS 解析或 TCP 连接失败，通常因网络限制、错误的主机/端口或防火墙阻止出站流量。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Configure a proxy if the environment requires one:

async with aiohttp.ClientSession() as s:
    async with s.get(url, proxy='http://proxy.local:8080') as r:
        ...
   ```
2. **** (85% 成功率)
   ```
   Verify DNS and connectivity first:

import socket
socket.gethostbyname('api.example.com')
# then retry with aiodns resolver if needed
   ```

## 无效尝试

- **** — Connection is refused or unreachable; a longer timeout only delays the same error. (80% 失败率)
- **** — The failure occurs before the TLS handshake; ssl=False does not help when TCP connect fails. (85% 失败率)
