{
  "id": "python/starlette-cors-missing-headers",
  "signature": "RuntimeError: CORS headers are missing. Use 'Access-Control-Allow-Origin' header.",
  "signature_zh": "运行时错误：缺少 CORS 头。请使用 'Access-Control-Allow-Origin' 头。",
  "regex": "RuntimeError:\\ CORS\\ headers\\ are\\ missing\\.\\ Use\\ 'Access\\-Control\\-Allow\\-Origin'\\ header\\.",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Starlette does not automatically add CORS headers; you must use a middleware like CORSMiddleware.",
  "root_cause_type": "generic",
  "root_cause_zh": "Starlette 不会自动添加 CORS 头；您必须使用像 CORSMiddleware 这样的中间件。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Manually setting headers in each response",
      "why_fails": "Preflight OPTIONS requests are not handled.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a custom middleware that only adds headers on some routes",
      "why_fails": "CORS must be applied globally.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add CORSMiddleware to the application",
      "success_rate": 0.95,
      "how": "from starlette.middleware.cors import CORSMiddleware\napp.add_middleware(CORSMiddleware, allow_origins=['*'])",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the CORSMiddleware with specific origins",
      "success_rate": 0.9,
      "how": "app.add_middleware(CORSMiddleware, allow_origins=['https://example.com'], allow_methods=['GET'])",
      "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-08-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}