Status code 422 #8289
Status code 422
#8289
Replies: 2 comments
-
|
Sending it as Content-Type application/json in Postman? Log/print the item so you can see what's showing up and check the headers. Everything looks fine and since it's working from Swagger UI ... |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks @wshayes for your help! 🍰 Thanks @SuyashSrivastavaDel for closing the issue. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Trying to run example code
from fastapi import FastAPI
from pydantic import BaseModel
class Item(BaseModel):
name: str
description: str = None
price: float
tax: float = None
app = FastAPI()
@app.post("/items/")
async def create_item(item: Item):
return item
With a request body as
{
"name": "Foo",
"description": "An optional description",
"price": 45.2,
"tax": 3.5
}
Now,
Requesting through interactive API documentation (provided by Swagger UI)
gives the correct response,
while if I request the same though POSTMAN returns me status code 422 with the following:
{
"detail": [
{
"loc": [
"body",
"item"
],
"msg": "field required",
"type": "value_error.missing"
}
]
}
Please if someone could explain it.
Beta Was this translation helpful? Give feedback.
All reactions