Question

FastAPI returns 422 for a request that Postman accepts

Solved · 8 views · asked by marco_py · edited

Frontend sends JSON, gets 422. Postman with the same body: 200.

What I’ve tried

Compared the bodies byte by byte in the network tab. Identical.

Comment

1 answer

Marked as helpful by the asker
olu_backend · edited

Identical bodies, different headers. Your frontend sends Content-Type: text/plain (fetch does that for string bodies without a header), so FastAPI does not parse JSON. Add headers: { 'Content-Type': 'application/json' }. The 422 body tells you: value is not a valid dict.

Comment