{
  "id": "python/fastapi-oauth2-token-error",
  "signature": "fastapi.exceptions.HTTPException: 401 Unauthorized: Not authenticated",
  "signature_zh": "FastAPI HTTP异常：401未授权：未验证",
  "regex": "fastapi\\.exceptions\\.HTTPException:\\ 401\\ Unauthorized:\\ Not\\ authenticated",
  "domain": "python",
  "category": "auth_error",
  "subcategory": null,
  "root_cause": "The request does not contain a valid OAuth2 token or the token is missing.",
  "root_cause_type": "generic",
  "root_cause_zh": "请求不包含有效的OAuth2令牌或令牌缺失。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Removing authentication from the endpoint",
      "why_fails": "Exposes the endpoint without security.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a hardcoded token without validation",
      "why_fails": "Insecure; token can be easily guessed.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Include a valid OAuth2 token in the Authorization header",
      "success_rate": 0.95,
      "how": "Authorization: Bearer <your_token>",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement token validation using OAuth2PasswordBearer",
      "success_rate": 0.9,
      "how": "from fastapi.security import OAuth2PasswordBearer\noauth2_scheme = OAuth2PasswordBearer(tokenUrl=\"token\")\n@app.get('/protected')\nasync def protected(token: str = Depends(oauth2_scheme)):\n    return {\"token\": token}",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}