# aiohttp 客户端异常：响应未消耗

- **ID:** `python/aiohttp-client-response-not-consumed`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在会话关闭前未完全读取或释放响应体，导致资源泄漏。

## 版本兼容性

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

## 解决方案

1. **Always read the response body using async with** (95% 成功率)
   ```
   async with session.get(url) as resp:
    data = await resp.text()
   ```
2. **Explicitly consume the response with resp.read()** (90% 成功率)
   ```
   resp = await session.get(url)
await resp.read()  # or resp.release() after reading
   ```

## 无效尝试

- **Calling resp.release() but not reading the body** — release() does not consume the body; it only releases the connection. The response remains unconsumed. (50% 失败率)
- **Using resp.text() with a timeout that is too short** — If the timeout expires, the body may be partially read, leaving the response unconsumed. (40% 失败率)
