From 8de59f03a09be6567ee7a877ce9bbbabbe0b9a50 Mon Sep 17 00:00:00 2001 From: Joseph McCullough Date: Tue, 8 Nov 2011 01:37:39 -0600 Subject: [PATCH 1/3] Added POST to quick start. Modified GET in doc to use httpbin --- docs/user/quickstart.rst | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 17e503a2..b730c6ed 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -25,19 +25,40 @@ Making a standard request with Requests is very simple. Let's get GitHub's public timeline :: - r = requests.get('https://github.com/timeline.json') + r = requests.get("http://httpbin.org/get") Now, we have a :class:`Response` object called ``r``. We can get all the information we need from this. + Response Content ---------------- We can read the content of the server's response:: >>> r.content - '[{"repository":{"open_issues":0,"url":"https://github.com/... + '{\n "url": "http://httpbin.org/get", \n "headers": ... + + +Make a POST Request +------------------ + +POST requests are equally simple :: + + >>> r = requests.post("http://httpbin.org/post") + + +Suppose you want to send data over HTTP. Simply pass a data +argument to the requests.post method with your dictionary :: + + >>> dataDict = {"key1":"value1", "key2":"value2"} + >>> r = requests.post("http://httpbin.org/post", data=dataDict) + >>> r.content + '{\n "origin": "::ffff:YourIpAddress", \n "files": {}, \n "form": {\n "key2": "value2", \n "key1": "value1"\n }, + +Note the data= argument is equivalent to -d in cURL scripts. dataDict will +be form-encoded. Response Status Codes @@ -165,3 +186,4 @@ Requests supports it!:: ----------------------- Ready for more? Check out the :ref:`advanced ` section. + From 827b2340a242c0882df2173744a8951f7ca88b14 Mon Sep 17 00:00:00 2001 From: Joseph McCullough Date: Tue, 8 Nov 2011 02:23:32 -0600 Subject: [PATCH 2/3] Forgot to delete line mentioning Github in GET section --- docs/user/quickstart.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index b730c6ed..4bebe95c 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -23,7 +23,7 @@ Make a GET Request Making a standard request with Requests is very simple. -Let's get GitHub's public timeline :: +Let's use httpbin to test our requests. :: r = requests.get("http://httpbin.org/get") From 1031ec494212076a5e1b9d5398a95c96cb7c561e Mon Sep 17 00:00:00 2001 From: Joseph McCullough Date: Tue, 8 Nov 2011 12:10:06 -0600 Subject: [PATCH 3/3] Reverted GET example back to Github. --- docs/user/quickstart.rst | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 4bebe95c..69e86c40 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -23,22 +23,21 @@ Make a GET Request Making a standard request with Requests is very simple. -Let's use httpbin to test our requests. :: +Let's get GitHub's public timeline :: - r = requests.get("http://httpbin.org/get") + r = requests.get('https://github.com/timeline.json') Now, we have a :class:`Response` object called ``r``. We can get all the information we need from this. - Response Content ---------------- We can read the content of the server's response:: >>> r.content - '{\n "url": "http://httpbin.org/get", \n "headers": ... + '[{"repository":{"open_issues":0,"url":"https://github.com/... Make a POST Request @@ -55,12 +54,11 @@ argument to the requests.post method with your dictionary :: >>> dataDict = {"key1":"value1", "key2":"value2"} >>> r = requests.post("http://httpbin.org/post", data=dataDict) >>> r.content - '{\n "origin": "::ffff:YourIpAddress", \n "files": {}, \n "form": {\n "key2": "value2", \n "key1": "value1"\n }, + '{\n "origin": "::ffff:YourIpAddress", \n "files": {}, \n "form": {\n "key2": "value2", \n "key1": "value1"\n }, ... Note the data= argument is equivalent to -d in cURL scripts. dataDict will be form-encoded. - Response Status Codes --------------------- @@ -186,4 +184,3 @@ Requests supports it!:: ----------------------- Ready for more? Check out the :ref:`advanced ` section. -