python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: body required
ID: python/fastapi-request-body-empty
80%Fix Rate
82%Confidence
0Evidence
2026-05-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
请求未提供 body,但端点声明了必需的身体参数。
generic中文
请求未提供 body,但端点声明了必需的身体参数。
Workarounds
-
90% success
使用 `Body(None)` 或 `Optional[Model] = None` 使请求体可选。
-
85% success
确保客户端发送有效的 JSON 请求体。
Dead Ends
Common approaches that don't work:
-
70% fail
尝试使用 `Body(...)` 但未设置默认值,导致请求体必须存在。
-
50% fail
尝试在客户端发送空 JSON,但 FastAPI 仍视为缺失。