Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errror parsing data in python FastAPI

I'm learning to use FastAPI, and I'm getting this error over and over again while implementing a simple API and I've not being able to figure out why

"detail": "There was an error parsing the body"

This happends me on this two endpoints:

Full code: Code Repository

snippet:

app_v1 = FastAPI(root_path='/v1')

# JWT Token request
@app_v1.post('/token')
async def login_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
    jwt_user_dict = {"username": form_data.username, "password": form_data.password}
    jwt_user = JWTUser(**jwt_user_dict)
    user = authenticate_user(jwt_user)
    if user is None:
        return HTTP_401_UNAUTHORIZED
    jwt_token = create_jwt_token(user)
    return {"token": jwt_token}

request:

enter image description here

enter image description here

@app_v1.post("/user/photo")
async def update_photo(response: Response, profile_photo: bytes = File(...)):
    response.headers['x-file-size'] = str(len(profile_photo))
    response.set_cookie(key='cookie-api', value="test")
    return {"profile photo size": len(profile_photo)}

request: enter image description here

like image 702
Rodrigo A Avatar asked Sep 17 '25 07:09

Rodrigo A


1 Answers

I acomplished to figure out, it was because when FastAPI was installed, it didn't install python-multipart, so with this package missing everything that needs multipart falls

After installing it works fine

Thanks

like image 106
Rodrigo A Avatar answered Sep 19 '25 20:09

Rodrigo A