python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: JSON 解码错误:期望值:第 1 行第 1 列 (字符 0)
fastapi.exceptions.RequestValidationError: JSON decode error Expecting value: line 1 column 1 (char 0)
ID: python/fastapi-json-decode-error
80%修复率
86%置信度
0证据数
2024-08-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
客户端发送了空请求体或非 JSON 请求体,而端点期望 application/json。
English
The client sent an empty or non-JSON body while the endpoint expects application/json.
解决方案
-
92% 成功率
async def create(item: Item | None = None): ...
-
88% 成功率
from fastapi import Body async def create(item: Item = Body(default=None)): ...
无效尝试
常见但无效的做法:
-
85% 失败
Header alone does not provide parseable JSON; still fails.
-
90% 失败
Parsing occurs before the handler in FastAPI.