I'm trying to test uploading a file to FastApi, but I keep getting 422 Validation Error. The file upload works in OpenApi interface, but not with the test below.
The router:
@router.post("/files")
def file_contents(files: List[UploadFile]):
return someprocessing(files)
The test (using TestClient
from FastApi):
response = client.post(
url="/files",
files={"files": ("file.xlsx", open("./test_files/file.xlsx", "rb"))},
headers={**auth_headers, **{"Content-Type": "multipart/form-data"}},
)
The error:
{"detail":[{"loc":["body"],"msg":"value is not a valid dict","type":"type_error.dict"}]}
Update: All good I was sending files to a different url...