python
encoding_error
ai_generated
true
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
ID: python/starlette-json-response-encoding
80%Fix Rate
82%Confidence
0Evidence
2025-03-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
尝试将非 UTF-8 编码的数据作为 JSON 响应返回。
generic中文
尝试将非 UTF-8 编码的数据作为 JSON 响应返回。
Workarounds
-
95% success
data = data.encode('utf-8').decode('utf-8') return JSONResponse({'data': data})
Dead Ends
Common approaches that don't work:
-
80% fail
会导致数据损坏,且不兼容 JSON
-
90% fail
会丢失数据,且客户端无法解析