clarify 415 vs 400 errors for request.json (#5827)
This commit is contained in:
parent
25642fd1fd
commit
30da640ffe
1 changed files with 5 additions and 3 deletions
|
|
@ -136,7 +136,8 @@ In general, prefer sending request data as form data, as would be used
|
||||||
when submitting an HTML form. JSON can represent more complex data, but
|
when submitting an HTML form. JSON can represent more complex data, but
|
||||||
unless you need that it's better to stick with the simpler format. When
|
unless you need that it's better to stick with the simpler format. When
|
||||||
sending JSON data, the ``Content-Type: application/json`` header must be
|
sending JSON data, the ``Content-Type: application/json`` header must be
|
||||||
sent as well, otherwise Flask will return a 400 error.
|
sent as well, otherwise Flask will return a 415 Unsupported Media Type
|
||||||
|
error.
|
||||||
|
|
||||||
.. code-block:: javascript
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
|
@ -244,8 +245,9 @@ Receiving JSON in Views
|
||||||
|
|
||||||
Use the :attr:`~flask.Request.json` property of the
|
Use the :attr:`~flask.Request.json` property of the
|
||||||
:data:`~flask.request` object to decode the request's body as JSON. If
|
:data:`~flask.request` object to decode the request's body as JSON. If
|
||||||
the body is not valid JSON, or the ``Content-Type`` header is not set to
|
the body is not valid JSON, a 400 Bad Request error will be raised. If
|
||||||
``application/json``, a 400 Bad Request error will be raised.
|
the ``Content-Type`` header is not set to ``application/json``, a 415
|
||||||
|
Unsupported Media Type error will be raised.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue