{
  "id": "python/pytest-httpx-mock-interface-mismatch",
  "signature": "httpx.ConnectError: [Errno -2] Name or service not known",
  "signature_zh": "httpx.ConnectError: [Errno -2] 无法解析名称或服务",
  "regex": "httpx\\.ConnectError:\\ \\[Errno\\ \\-2\\]\\ Name\\ or\\ service\\ not\\ known",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "respx/httpx mock router wasn't registered for the URL being requested, or the client instance was created before the mock was installed, so the real network call is attempted.",
  "root_cause_type": "generic",
  "root_cause_zh": "respx/httpx mock 路由未注册所请求的 URL，或客户端实例在 mock 安装之前创建，导致尝试真实网络调用。",
  "versions": [
    {
      "version": "0.20.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "0.21.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Over-broad; hides typos in URLs and returns the same mock for every request, defeating per-endpoint assertions.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Bypasses proxies but doesn't prevent the real DNS lookup; the error persists.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "import httpx, respx\n\n@respx.mock\ndef test_get():\n    respx.get('https://api.example.com/users/1').mock(\n        return_value=httpx.Response(200, json={'id': 1})\n    )\n    with httpx.Client() as c:\n        r = c.get('https://api.example.com/users/1')\n    assert r.json()['id'] == 1",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "with respx.mock(assert_all_called=True) as router:\n    router.get('https://api.example.com/').mock(return_value=httpx.Response(200))\n    run_code()",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-05-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}