# RuntimeError: 会话已关闭

- **ID:** `python/aiohttp-session-client-closed`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

aiohttp.ClientSession 已被关闭（通过 async with 或 session.close()），但仍有协程尝试用它发起请求。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   session = aiohttp.ClientSession()
try:
    await fetch_all(session)
finally:
    await session.close()
   ```
2. **** (93% 成功率)
   ```
   async with aiohttp.ClientSession() as session:
    async with session.get(url) as resp:
        data = await resp.text()
   ```

## 无效尝试

- **** — Reassigning does not resurrect the closed object; any references held elsewhere still point to the closed session. (70% 失败率)
- **** — The connector is also closed with the session; manual connect raises the same error. (85% 失败率)
