# httpx.ConnectTimeout: 连接到主机'api.example.com'超时（5000毫秒后），连接被拒绝

- **ID:** `python/httpx-connecttimeout-firewall-block`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

远程服务器主动拒绝连接，通常是由于防火墙规则或服务未运行。

## 版本兼容性

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

## 解决方案

1. **Check if the server is reachable via telnet or ping** (80% 成功率)
   ```
   telnet api.example.com 443
# If refused, contact server administrator or check firewall rules
   ```
2. **Use a different port or protocol if available** (60% 成功率)
   ```
   httpx.get('http://api.example.com:8080')  # if alternative port exists
   ```

## 无效尝试

- **Increasing timeout to wait longer** — The connection is refused immediately, so a longer timeout does not help. (90% 失败率)
- **Retrying with the same parameters** — The server continues to refuse connections until the underlying issue is resolved. (95% 失败率)
