{
  "id": "python/starlette-http-exception-not-callable",
  "signature": "TypeError: 'HTTPException' object is not callable",
  "signature_zh": "类型错误: 'HTTPException' 对象不可调用",
  "regex": "TypeError:\\ 'HTTPException'\\ object\\ is\\ not\\ callable",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "当在Starlette或FastAPI中将HTTPException实例（而非异常类）作为依赖项或中间件传递时，框架尝试调用它，导致类型错误。",
  "root_cause_type": "generic",
  "root_cause_zh": "在Starlette或FastAPI中，将HTTPException实例（而非异常类）作为依赖项或中间件传递时，框架会尝试调用它，从而引发类型错误。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "尝试将HTTPException作为函数导入并直接调用",
      "why_fails": "HTTPException是类，不是函数，直接调用不会触发异常，但作为依赖项仍会出错。",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "在依赖项中使用raise HTTPException而不是return",
      "why_fails": "在依赖项中raise会立即中断请求，但若返回实例则仍会引发错误。",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "使用Starlette的HTTPException类作为异常抛出，而非作为返回值",
      "success_rate": 0.95,
      "how": "from starlette.exceptions import HTTPException; raise HTTPException(status_code=404, detail='Not found')",
      "condition": "",
      "sources": []
    },
    {
      "action": "在依赖项中返回Response对象替代异常实例",
      "success_rate": 0.9,
      "how": "from starlette.responses import JSONResponse; return JSONResponse(status_code=404, content={'detail': 'Not found'})",
      "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-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}