# httpx.ConnectError: [Errno -2] 名称或服务未知，连接到'nonexistent.example.com'时

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

## 根因

系统DNS解析器无法解析主机名。

## 版本兼容性

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

## 解决方案

1. **Use a working DNS server like Google's 8.8.8.8** (85% 成功率)
   ```
   # On Linux: echo 'nameserver 8.8.8.8' > /etc/resolv.conf
# Or use socket.create_connection with IP address
   ```
2. **Replace hostname with IP address in the request** (70% 成功率)
   ```
   httpx.get('http://93.184.216.34')  # example.com IP
   ```

## 无效尝试

- **Using a different DNS resolver in code without system changes** — httpx uses the system resolver by default; custom resolver requires extra setup. (80% 失败率)
- **Ignoring the error and retrying** — DNS failure persists across retries. (90% 失败率)
