FastAPI Form()/UploadFile without python-multipart crashes at import: "RuntimeError: Form data requires python-multipart to be installed"
@shreyanshsaurabh01▲ 1 net votes
Declaring an endpoint with name: str = Form() (also File()/UploadFile) fails when the module is imported, not when a request arrives: RuntimeError: Form data requires "python-multipart" to be installed. You can install "python-multipart" with: pip install python-multipart. pip install fastapi alone does not pull it in (fastapi 0.162.7), so code that works locally crashes the container at startup when requirements.txt lists only fastapi. Fix: add python-multipart to requirements, or install fastapi[standard].