From 5a9097dc4b8c90a3b501a403177ec5314064e395 Mon Sep 17 00:00:00 2001 From: Smiley Barry Date: Fri, 14 Aug 2015 17:15:51 +0300 Subject: [PATCH 1/2] Update quickstart.rst Added note about the `json` parameter in `requests.post`. --- docs/user/quickstart.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 7b14610c..2277528c 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -229,6 +229,15 @@ For example, the GitHub API v3 accepts JSON-Encoded POST/PATCH data:: >>> payload = {'some': 'data'} >>> r = requests.post(url, data=json.dumps(payload)) + +You can use the `json` parameter (added in version 2.4.2) to avoid encoding the +data yourself: + + >>> import json + >>> url = 'https://api.github.com/some/endpoint' + >>> payload = {'some': 'data'} + + >>> r = requests.post(url, json=payload) POST a Multipart-Encoded File From b1de7e728721750c21988895d3c9de8f627b81ea Mon Sep 17 00:00:00 2001 From: Smiley Barry Date: Fri, 14 Aug 2015 17:31:54 +0300 Subject: [PATCH 2/2] Changed phrasing to be a little clearer. --- docs/user/quickstart.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 2277528c..3e2730bb 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -230,8 +230,8 @@ For example, the GitHub API v3 accepts JSON-Encoded POST/PATCH data:: >>> r = requests.post(url, data=json.dumps(payload)) -You can use the `json` parameter (added in version 2.4.2) to avoid encoding the -data yourself: +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: >>> import json >>> url = 'https://api.github.com/some/endpoint'