python
network_error
ai_generated
partial
httpx.ConnectError: [Errno 111] Connection refused
ID: python/httpx-connect-error-all-connection-attempts-failed
80%Fix Rate
83%Confidence
0Evidence
2024-09-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8+ | active | — | — | — |
| 3.9+ | active | — | — | — |
| 3.10+ | active | — | — | — |
| 3.11+ | active | — | — | — |
| 3.12+ | active | — | — | — |
Root Cause
The target host/port is not accepting TCP connections; server is down, wrong port, or blocked by firewall.
generic中文
目标主机/端口未接受 TCP 连接;服务器已关闭、端口错误或被防火墙阻止。
Workarounds
-
85% success
import httpx, asyncio for delay in (1, 2, 4, 8): try: async with httpx.AsyncClient() as c: r = await c.get(url) break except httpx.ConnectError: await asyncio.sleep(delay) -
88% success
transport = httpx.AsyncHTTPTransport(retries=3) async with httpx.AsyncClient(transport=transport) as c: r = await c.get(url)
Dead Ends
Common approaches that don't work:
-
90% fail
Connection refused is immediate; timeouts are irrelevant.
-
85% fail
The failure occurs before any HTTP exchange.