Skip to content

Commit

Permalink
Make the data vs json parameters more clear (#5382)
Browse files Browse the repository at this point in the history
As https://stackoverflow.com/q/26685248/2693875 question
and answer popularity shows that there is a lot of people who
do not understand the distinction.
  • Loading branch information
gdubicki authored Dec 29, 2021
1 parent 77d1e9a commit ab38e2c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/user/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,12 @@ For example, the GitHub API v3 accepts JSON-Encoded POST/PATCH data::

>>> r = requests.post(url, data=json.dumps(payload))

Instead of encoding the ``dict`` yourself, you can also pass it directly using
the ``json`` parameter (added in version 2.4.2) and it will be encoded automatically::
Please note that the above code will NOT add the ``Content-Type`` header
(so in particular it will NOT set it to ``application/json``).

If you need that header set and you don't want to encode the ``dict`` yourself,
you can also pass it directly using the ``json`` parameter (added in version 2.4.2)
and it will be encoded automatically:

>>> url = 'https://api.github.com/some/endpoint'
>>> payload = {'some': 'data'}
Expand All @@ -293,8 +297,6 @@ the ``json`` parameter (added in version 2.4.2) and it will be encoded automatic

Note, the ``json`` parameter is ignored if either ``data`` or ``files`` is passed.

Using the ``json`` parameter in the request will change the ``Content-Type`` in the header to ``application/json``.

POST a Multipart-Encoded File
-----------------------------

Expand Down

0 comments on commit ab38e2c

Please sign in to comment.