I am trying to reach a fastAPI endpoint using the python requests, however, any request always returns a 422 Unprocessable Entity error. I have looked at other similar posts, such as this one, but to no avail. No matter if I send the request_dict as data
, json
, or params
, I get the same error.
Here is where I define my FastAPI endpoint:
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_methods=['*'],
allow_headers=['*']
)
class ModelInterface(BaseModel):
name: str
contents: str
languages: List[str]
@app.post("my_endpoint")
async def determine_file(model: ModelInterface) -> Dict[str,str]:
name = model.name
contents = model.contents
languages = model.languages
<logic here>
And here is what tries to request this endpoint:
def call_filedet(name: str, contents: str, languages: str) -> Dict[str, str]:
url = "http://my_url/my_endpoint"
request_dict = {
"name": name,
"contents": contents,
"languages": languages
}
response = requests.post(url, params=request_dict)
Does anyone know what the issue may be? I'm pretty stuck and don't know how to debug because the only response I get is the 422 error message.