# requests.exceptions.ConnectionError: HTTPConnectionPool(host='nonexistent.example.com', port=80): 超过最大重试次数 (由NewConnectionError('<urllib3.connection.HTTPConnection object at 0x...>: 无法建立新连接：[Errno -2] 名称或服务未知')引起)

- **ID:** `python/requests-connectionerror-dns-failure`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

主机名无法解析为IP地址，因为它不存在或DNS配置错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Verify the hostname spelling and domain existence** (90% 成功率)
   ```
   Check the URL for typos, e.g., requests.get('https://example.com') instead of 'exampl.com'
   ```
2. **Use a public DNS server like 8.8.8.8** (80% 成功率)
   ```
   Configure system DNS to 8.8.8.8 or use socket.setdefaulttimeout(10) with a custom resolver
   ```

## 无效尝试

- **Increasing the retry count** — Retrying does not fix DNS resolution; the hostname remains unresolved. (95% 失败率)
- **Using a VPN or proxy without checking DNS** — A VPN may change DNS servers, but if the hostname is invalid, it still fails. (70% 失败率)
