Skip to content
Advertisement

HTTPS POST to query FastAPI using python requests

I am trying to serve a Neural Network using FastAPI.

JavaScript

The manual site http://localhost:8000/docs#/default/predict_predict_post works fine and translates into the following curl command:

JavaScript

which also works. When I try to query the API using python requests:

JavaScript

I only get the “422 Unprocessable Entity” Errors. Where am I going wrong here?

Advertisement

Answer

You provide a data argument to requests.post, which does a POST with Content-Type: application/x-www-form-urlencoded, which is not JSON.

Consider using requests.post(url, json=data) and you should be fine.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement