{
  "id": "python/fastapi-cors-error-origin-not-allowed",
  "signature": "CORS: origin 'http://example.com' not allowed by Access-Control-Allow-Origin",
  "signature_zh": "CORS 错误：来源 'http://example.com' 未被 Access-Control-Allow-Origin 允许",
  "regex": "CORS:\\ origin\\ 'http://example\\.com'\\ not\\ allowed\\ by\\ Access\\-Control\\-Allow\\-Origin",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "FastAPI 应用未正确配置 CORS 中间件以允许特定来源",
  "root_cause_type": "generic",
  "root_cause_zh": "FastAPI 应用未正确配置 CORS 中间件以允许特定来源",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "只在前端设置请求头而不修改后端",
      "why_fails": "CORS 策略由服务器控制，前端无法绕过",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "在 FastAPI 中手动添加响应头但未使用中间件",
      "why_fails": "可能被其他中间件覆盖或处理不当",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "使用 CORSMiddleware 并添加允许的来源",
      "success_rate": 0.95,
      "how": "from fastapi.middleware.cors import CORSMiddleware\napp.add_middleware(CORSMiddleware, allow_origins=['http://example.com'])",
      "condition": "",
      "sources": []
    },
    {
      "action": "允许所有来源（仅用于开发）",
      "success_rate": 0.9,
      "how": "app.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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}