{
  "id": "python/aiohttp-session-outside-context",
  "signature": "RuntimeError: Session is closed",
  "signature_zh": "RuntimeError: 会话已关闭",
  "regex": "RuntimeError:\\ Session\\ is\\ closed",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An aiohttp.ClientSession was used after exiting its async with block (which calls close()), or after session.close() was awaited.",
  "root_cause_type": "generic",
  "root_cause_zh": "在退出 async with 块（会调用 close()）之后，或在 await session.close() 之后，仍使用了 aiohttp.ClientSession。",
  "versions": [
    {
      "version": "3.9+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The context manager closes the session on exit; reusing it always raises.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Closed sessions cannot issue new requests; the connector is shut down.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "async with aiohttp.ClientSession() as session:\n    async with session.get(url) as r:\n        data = await r.text()\n    async with session.get(url2) as r2:\n        ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "session = aiohttp.ClientSession()\ntry:\n    async with session.get(url) as r:\n        ...\nfinally:\n    await session.close()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}