I have this fastAPI POST endpoint (the comments are what I tested according to what I found on the web):
from fastapi import FastAPI
from pydantic import BaseModel
from typing import Any
from fastapi import Body
app = FastAPI()
class Data_schema(BaseModel):
# jsonObj: str
# data: Any
somekey: str
@app.post("/")
async def get_item(payload: Data_schema):
# async def get_item(payload):
# async def get_item(payload: str = Body(..., embed=True)):
return payload
And I test it with:
import requests
import json
data = {'somekey': 'somevalue'}
jsonObj = json.dumps(data, indent=4, default=str)
# jsonObj = json.dumps(data)
requests.post('http://127.0.0.1:8000/', data=data)
# requests.post('http://127.0.0.1:8000/', json=jsonObj)
# requests.post('http://127.0.0.1:8000/', json=data)
# requests.post('http://127.0.0.1:8000/', json=jsonObj)
I cannot get something else than 422 Unprocessable Entity
. I am using python 3.10. Where do I do wrong ?
Thank you