{
  "id": "python/starlette-route-param-type",
  "signature": "ValueError: Invalid type for path parameter 'id': expected int, got str",
  "signature_zh": "值错误：路径参数 'id' 的类型无效：应为 int，实际为 str",
  "regex": "ValueError:\\ Invalid\\ type\\ for\\ path\\ parameter\\ 'id':\\ expected\\ int,\\ got\\ str",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Starlette route path parameters must be type-converted; if the URL provides a string but the handler expects int, this error occurs if conversion fails.",
  "root_cause_type": "generic",
  "root_cause_zh": "Starlette 路由路径参数必须进行类型转换；如果 URL 提供字符串但处理程序期望 int，转换失败时会报错。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using a string parameter and converting manually",
      "why_fails": "Starlette auto-converts based on type hints; manual conversion may cause mismatch.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Not specifying a type hint",
      "why_fails": "Without type hint, Starlette treats it as str.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use int type hint in the route parameter",
      "success_rate": 0.95,
      "how": "async def handler(request):\n    id = request.path_params['id']\n    # id is already an int",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a converter in the route pattern",
      "success_rate": 0.9,
      "how": "routes = [Route('/items/{id:int}', handler)]",
      "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-11-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}