python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: Body 有 1 个验证错误 body -> username 字段必填 (type=value_error.missing)
fastapi.exceptions.RequestValidationError: 1 validation error for Body body -> username field required (type=value_error.missing)
ID: python/fastapi-missing-form-data
80%修复率
85%置信度
0证据数
2024-10-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
| 0.110+ | active | — | — | — |
根因分析
端点声明了 Form(...) 但客户端发送 JSON,或声明了 JSON body 但客户端发送 form-urlencoded。
English
Endpoint declares Form(...) but client sends JSON, or declares JSON body but client sends form-urlencoded.
解决方案
-
95% 成功率
pip install python-multipart # required for Form/File
-
90% 成功率
async def login(username: str = Form(...), password: str = Form(...)) # and client must send application/x-www-form-urlencoded
无效尝试
常见但无效的做法:
-
80% 失败
Server starts but Form parsing still fails at runtime.
-
65% 失败
Breaks form clients; still 422 for the other content type.