python
network_error
ai_generated
true
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.example.com:443 ssl:default [Connect call failed]
ID: python/aiohttp-cannot-connect-to-host
80%Fix Rate
87%Confidence
0Evidence
2024-07-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
Root Cause
DNS resolution or TCP connection to the target host failed, often due to network restrictions, wrong host/port, or firewall blocking outbound traffic.
generic中文
对目标主机的 DNS 解析或 TCP 连接失败,通常因网络限制、错误的主机/端口或防火墙阻止出站流量。
Workarounds
-
90% success
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: ... -
85% success
Verify DNS and connectivity first: import socket socket.gethostbyname('api.example.com') # then retry with aiodns resolver if needed
Dead Ends
Common approaches that don't work:
-
80% fail
Connection is refused or unreachable; a longer timeout only delays the same error.
-
85% fail
The failure occurs before the TLS handshake; ssl=False does not help when TCP connect fails.