I'm just having a go at using fastapi for hobbyiest purposes. I am getting the 422 unprocessable entity error with my post request
I've created a pydantic model for my products
class post_products(BaseModel):
id: int
description: str
price: int
Then have a post endpoint created
@app.post('/send/data', status_code=201)
async def process_data(product: post_products):
products_list.append(product)
if(product in products_list):
return True
which i believe functions like, it takes in a post_products instance adds it to the products_list and then returns true if the add was successful, I then call this endPoint with
product = post_products(id=12,description='hello', price=93) creates and instance of the class
product = product.model_dump() makes this instance into a dictionary
response = requests.post("http://127.0.0.1:8000/send/data", data= product)
Sorry Gordon i've updated it with the result. The product is a dict and its this
{'id': 12, 'description': 'hello', 'price': 93}