python runtime_error ai_generated true

fastapi.exceptions.RequestValidationError: value is not a valid dict (type=type_error.dict)

ID: python/fastapi-form-data-required

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
0.100.x active
0.110.x active

Root Cause

Sending form data but endpoint expects JSON, or vice versa.

generic

中文

发送表单数据但端点期望 JSON,或反之。

Workarounds

  1. 95% success
    from fastapi import Form
    @app.post('/login')
    async def login(username: str = Form(...), password: str = Form(...)):
  2. 90% success
    For JSON: `Content-Type: application/json`; for form: `application/x-www-form-urlencoded`.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    If server expects form, JSON still fails.

  2. 80% fail

    Still expects JSON.