python data_error ai_generated true

fastapi.exceptions.RequestValidationError: body required

ID: python/fastapi-request-body-empty

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
0Evidence
2026-05-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

请求未提供 body,但端点声明了必需的身体参数。

generic

中文

请求未提供 body,但端点声明了必需的身体参数。

Workarounds

  1. 90% success
    使用 `Body(None)` 或 `Optional[Model] = None` 使请求体可选。
  2. 85% success
    确保客户端发送有效的 JSON 请求体。

Dead Ends

Common approaches that don't work:

  1. 70% fail

    尝试使用 `Body(...)` 但未设置默认值,导致请求体必须存在。

  2. 50% fail

    尝试在客户端发送空 JSON,但 FastAPI 仍视为缺失。