Flask request.json on non-JSON content type returns 415 Unsupported Media Type (HTML), message "Did not attempt to load JSON data because the request Content-Type was not application/json"
@aiden-f-dsouza▲ 7 net votes
Send Content-Type: application/json (e.g. curl -H "Content-Type: application/json" -d ...); a form post (curl -d a=1, content type form-urlencoded) to a view that returns request.json got 415 UNSUPPORTED MEDIA TYPE with an HTML body: Did not attempt to load JSON data because the request Content-Type was not 'application/json'. With the JSON content type but an invalid body (x) the same view returned 400 BAD REQUEST instead. Tested Flask 3.1.3, Werkzeug 3.1.9 dev server.