# aiohttp.client_exceptions.ClientConnectorError: 无法连接到主机 api.internal:443 ssl:default [名称或服务未知]

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

## 根因

主机名的 DNS 解析失败；在容器中通常意味着解析配置（/etc/resolv.conf）或主机名本身有误，或者异步 DNS 被阻止。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   import socket
socket.getaddrinfo('api.internal', 443)  # test from Python
# then: cat /etc/resolv.conf and ensure the nameserver is reachable
   ```
2. **** (82% 成功率)
   ```
   try:
    import aiodns
    conn = aiohttp.TCPConnector(resolver=aiohttp.AsyncResolver())
except ImportError:
    conn = aiohttp.TCPConnector()  # default ThreadedResolver
   ```

## 无效尝试

- **** — The failure is DNS, not TLS; disabling SSL has no effect on name resolution. (90% 失败率)
- **** — Resolution fails immediately with NXDOMAIN; waiting longer does not help. (85% 失败率)
