# asyncio异常：请求在5秒后超时

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

## 根因

aiohttp请求超过配置的超时时间，通常是由于网络或服务器缓慢。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.7 | active | — | — |
| 3.8 | active | — | — |
| 3.9 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   timeout = aiohttp.ClientTimeout(total=10); async with session.get(url, timeout=timeout) as resp:
   ```
2. **** (85% 成功率)
   ```
   await asyncio.wait_for(session.get(url), timeout=10)
   ```

## 无效尝试

- **** — Masks the problem and may hang indefinitely; not scalable. (50% 失败率)
- **** — Doesn't affect the request timeout; only delays execution. (90% 失败率)
