{
  "id": "python/pytest-requests-mock-adapter-not-active",
  "signature": "requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded with url: /v1/items (Caused by NewConnectionError(...))",
  "signature_zh": "requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.example.com', port=443): 超过最大重试次数，URL: /v1/items（由 NewConnectionError(...) 引起）",
  "regex": "requests\\.exceptions\\.ConnectionError:\\ HTTPSConnectionPool\\(host='api\\.example\\.com',\\ port=443\\):\\ Max\\ retries\\ exceeded\\ with\\ url:\\ /v1/items\\ \\(Caused\\ by\\ NewConnectionError\\(\\.\\.\\.\\)\\)",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "requests_mock.Mocker was used as a context manager but the client under test creates its own Session (or uses requests.Session() directly), which is not the session the adapter was mounted on.",
  "root_cause_type": "generic",
  "root_cause_zh": "requests_mock.Mocker 作为上下文管理器使用，但被测客户端创建了自己的 Session（或直接使用 requests.Session()），并非挂载了适配器的那个 session。",
  "versions": [
    {
      "version": "1.11.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.12.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Module-level mocker still only patches the default session; code that instantiates its own Session bypasses it.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Falls back to the real network, which is exactly what CI cannot access; the ConnectionError persists.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.94,
      "how": "import requests, requests_mock\n\ndef test_fetch():\n    session = requests.Session()\n    with requests_mock.Mocker(session=session) as m:\n        m.get('https://api.example.com/v1/items', json=[])\n        client = MyClient(session=session)\n        assert client.fetch_items() == []",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "@pytest.fixture\ndef mocked_session():\n    s = requests.Session()\n    with requests_mock.Mocker(session=s) as m:\n        yield s, m\n\ndef test_x(mocked_session):\n    s, m = mocked_session\n    m.get('https://api.example.com/v1/items', json=[])\n    assert MyClient(session=s).fetch_items() == []",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}