python
runtime_error
ai_generated
true
fastapi.exceptions.RequestValidationError:值不是有效的字典 (type=type_error.dict)
fastapi.exceptions.RequestValidationError: value is not a valid dict (type=type_error.dict)
ID: python/fastapi-form-data-required
80%修复率
88%置信度
0证据数
2026-01-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.100.x | active | — | — | — |
| 0.110.x | active | — | — | — |
根因分析
发送表单数据但端点期望 JSON,或反之。
English
Sending form data but endpoint expects JSON, or vice versa.
解决方案
-
95% 成功率
from fastapi import Form @app.post('/login') async def login(username: str = Form(...), password: str = Form(...)): -
90% 成功率
For JSON: `Content-Type: application/json`; for form: `application/x-www-form-urlencoded`.
无效尝试
常见但无效的做法:
-
60% 失败
If server expects form, JSON still fails.
-
80% 失败
Still expects JSON.