python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: 1 validation error for Body body -> username field required (type=value_error.missing)
ID: python/fastapi-missing-form-data
80%Fix Rate
85%Confidence
0Evidence
2024-10-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
| 0.110+ | active | — | — | — |
Root Cause
Endpoint declares Form(...) but client sends JSON, or declares JSON body but client sends form-urlencoded.
generic中文
端点声明了 Form(...) 但客户端发送 JSON,或声明了 JSON body 但客户端发送 form-urlencoded。
Workarounds
-
95% success
pip install python-multipart # required for Form/File
-
90% success
async def login(username: str = Form(...), password: str = Form(...)) # and client must send application/x-www-form-urlencoded
Dead Ends
Common approaches that don't work:
-
80% fail
Server starts but Form parsing still fails at runtime.
-
65% fail
Breaks form clients; still 422 for the other content type.