Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the data vs json parameters more clear #5382

Merged
merged 1 commit into from Dec 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/user/quickstart.rst
Expand Up @@ -279,8 +279,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 @@ -289,8 +293,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