{
  "id": "python/starlette-cors-error",
  "signature": "RuntimeError: No 'Access-Control-Allow-Origin' header is present on the requested resource",
  "signature_zh": "运行时错误：请求的资源上不存在'Access-Control-Allow-Origin'头",
  "regex": "RuntimeError:\\ No\\ 'Access\\-Control\\-Allow\\-Origin'\\ header\\ is\\ present\\ on\\ the\\ requested\\ resource",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Starlette application does not have CORS middleware configured, so cross-origin requests are blocked by the browser.",
  "root_cause_type": "generic",
  "root_cause_zh": "Starlette应用未配置CORS中间件，因此跨域请求被浏览器阻止。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding CORS headers manually in the response",
      "why_fails": "Doesn't handle preflight OPTIONS requests, causing browser to block the actual request.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "Disabling CORS check in browser",
      "why_fails": "Not a production solution; only works for local testing.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add CORSMiddleware from Starlette",
      "success_rate": 0.95,
      "how": "from starlette.middleware.cors import CORSMiddleware\napp.add_middleware(\n    CORSMiddleware,\n    allow_origins=[\"*\"],\n    allow_methods=[\"*\"],\n    allow_headers=[\"*\"],\n)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use FastAPI's built-in CORS middleware if using FastAPI",
      "success_rate": 0.9,
      "how": "from fastapi.middleware.cors import CORSMiddleware\napp.add_middleware(CORSMiddleware, allow_origins=[\"*\"])",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}