{
  "id": "python/fastapi-405-method-not-allowed-cors",
  "signature": "405 Method Not Allowed on OPTIONS preflight request to /api/items",
  "signature_zh": "对 /api/items 的 OPTIONS 预检请求返回 405 方法不允许",
  "regex": "405\\ Method\\ Not\\ Allowed\\ on\\ OPTIONS\\ preflight\\ request\\ to\\ /api/items",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "CORSMiddleware added after router or with allow_methods not including OPTIONS; or route only allows POST.",
  "root_cause_type": "generic",
  "root_cause_zh": "CORSMiddleware 在路由之后添加，或 allow_methods 未包含 OPTIONS；或路由仅允许 POST。",
  "versions": [
    {
      "version": "0.100+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "0.110+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Fails when CORSMiddleware is not registered first.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Default allow_methods is ['GET']; OPTIONS still blocked.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "app.add_middleware(CORSMiddleware, allow_origins=['http://localhost:3000'], allow_methods=['*'], allow_headers=['*'])  # add before routes",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Ensure the route decorator uses @app.post('/api/items') and CORSMiddleware is registered at startup.",
      "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-28",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}