{
  "id": "python/fastapi-unicodedecodeerror-request-body",
  "signature": "UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte",
  "signature_zh": "UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 0 的字节 0x80：无效的起始字节",
  "regex": "UnicodeDecodeError:\\ 'utf\\-8'\\ codec\\ can't\\ decode\\ byte\\ 0x80\\ in\\ position\\ 0:\\ invalid\\ start\\ byte",
  "domain": "python",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "Request body contains non-UTF-8 encoded data, such as binary or Latin-1.",
  "root_cause_type": "generic",
  "root_cause_zh": "请求体包含非 UTF-8 编码的数据，例如二进制或 Latin-1。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Setting app default encoding to latin-1 globally",
      "why_fails": "Breaks other parts expecting UTF-8.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring errors with errors='ignore'",
      "why_fails": "Data loss can occur.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Specify encoding when reading request body",
      "success_rate": 0.85,
      "how": "data = await request.body()\ntext = data.decode('latin-1')  # or 'utf-8' with errors='replace'",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use FastAPI's bytes type for raw data",
      "success_rate": 0.9,
      "how": "from fastapi import UploadFile\n@app.post('/upload')\nasync def upload(file: UploadFile):\n    content = await file.read()\n    # handle bytes as needed",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}