python
network_error
ai_generated
true
httpx.ConnectError: [Errno -2] Name or service not known while connecting to 'nonexistent.example.com'
ID: python/httpx-connecterror-dns-resolution-failure
80%Fix Rate
84%Confidence
0Evidence
2025-02-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The hostname cannot be resolved by the system's DNS resolver.
generic中文
系统DNS解析器无法解析主机名。
Workarounds
-
85% success Use a working DNS server like Google's 8.8.8.8
# On Linux: echo 'nameserver 8.8.8.8' > /etc/resolv.conf # Or use socket.create_connection with IP address
-
70% success Replace hostname with IP address in the request
httpx.get('http://93.184.216.34') # example.com IP
Dead Ends
Common approaches that don't work:
-
Using a different DNS resolver in code without system changes
80% fail
httpx uses the system resolver by default; custom resolver requires extra setup.
-
Ignoring the error and retrying
90% fail
DNS failure persists across retries.