python
network_error
ai_generated
true
requests.exceptions.ConnectionError: HTTPConnectionPool(host='nonexistent.example.com', port=80): 超过最大重试次数 (由NewConnectionError('<urllib3.connection.HTTPConnection object at 0x...>: 无法建立新连接:[Errno -2] 名称或服务未知')引起)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='nonexistent.example.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x...>: Failed to establish a new connection: [Errno -2] Name or service not known'))
ID: python/requests-connectionerror-dns-failure
80%修复率
84%置信度
0证据数
2024-05-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
主机名无法解析为IP地址,因为它不存在或DNS配置错误。
English
The hostname cannot be resolved to an IP address because it does not exist or DNS is misconfigured.
解决方案
-
90% 成功率 Verify the hostname spelling and domain existence
Check the URL for typos, e.g., requests.get('https://example.com') instead of 'exampl.com' -
80% 成功率 Use a public DNS server like 8.8.8.8
Configure system DNS to 8.8.8.8 or use socket.setdefaulttimeout(10) with a custom resolver
无效尝试
常见但无效的做法:
-
Increasing the retry count
95% 失败
Retrying does not fix DNS resolution; the hostname remains unresolved.
-
Using a VPN or proxy without checking DNS
70% 失败
A VPN may change DNS servers, but if the hostname is invalid, it still fails.