Skip to content
Myr

Make the `data` vs `json` parameters more clear (#5382)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Greg Dubicki · committed by GitHub · parent 77d1e9a · Browse files · 1 file+6 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−4 removed

  • other:+6 added−4 removed

1 file+6 added−4 removed

modified:docs/user/quickstart.rst+6 added-4 removed
281 unmodified lines
282 >>> payload = {'some': 'data'}283284 >>> r = requests.post(url, data=json.dumps(payload))285286Instead of encoding the ``dict`` yourself, you can also pass it directly using287the ``json`` parameter (added in version 2.4.2) and it will be encoded automatically::286Please note that the above code will NOT add the ``Content-Type`` header287(so in particular it will NOT set it to ``application/json``).288289If you need that header set and you don't want to encode the ``dict`` yourself,290you can also pass it directly using the ``json`` parameter (added in version 2.4.2)291and it will be encoded automatically:292293 >>> url = 'https://api.github.com/some/endpoint'294 >>> payload = {'some': 'data'}295296 >>> r = requests.post(url, json=payload)297298Note, the ``json`` parameter is ignored if either ``data`` or ``files`` is passed.299296Using the ``json`` parameter in the request will change the ``Content-Type`` in the header to ``application/json``.297300POST a Multipart-Encoded File301-----------------------------302303Requests makes it simple to upload Multipart-encoded files::
268 unmodified lines