# aiohttp.client_exceptions.ServerTimeoutError: 连接主机 https://slow.example.com 超时

- **ID:** `python/aiohttp-connector-timeout`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

服务器未在配置的 aiohttp.ClientTimeout 内完成 TCP/TLS 握手或响应，通常是因为端点过载或超时设置过于激进。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   timeout = aiohttp.ClientTimeout(total=30, connect=5, sock_read=10)
async with aiohttp.ClientSession(timeout=timeout) as s:
    await s.get(url)
   ```
2. **** (85% 成功率)
   ```
   for i in range(3):
    try:
        async with session.get(url) as r:
            return await r.text()
    except aiohttp.ServerTimeoutError:
        await asyncio.sleep(2 ** i)
   ```

## 无效尝试

- **** — Hangs forever on dead hosts and exhausts connection pool slots. (90% 失败率)
- **** — Handshake still fails on the sock_connect phase before the total timer matters. (75% 失败率)
