python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: JSON decode error Expecting value: line 1 column 1 (char 0)
ID: python/fastapi-json-decode-error
80%Fix Rate
86%Confidence
0Evidence
2024-08-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The client sent an empty or non-JSON body while the endpoint expects application/json.
generic中文
客户端发送了空请求体或非 JSON 请求体,而端点期望 application/json。
Workarounds
-
92% success
async def create(item: Item | None = None): ...
-
88% success
from fastapi import Body async def create(item: Item = Body(default=None)): ...
Dead Ends
Common approaches that don't work:
-
85% fail
Header alone does not provide parseable JSON; still fails.
-
90% fail
Parsing occurs before the handler in FastAPI.