From 9f6246a7b84a7889864b1b1be3545bc8801bf7df Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 13 Nov 2011 00:59:22 -0500 Subject: [PATCH 01/13] s --- docs/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index bab640b0..5491e98b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,7 +30,7 @@ Things shouldn’t be this way. Not in Python. See `the same code, without Requests `_. -Requests allow you to send **HEAD**, **GET**, **POST**, **PUT**, +Requests allows you to send **HEAD**, **GET**, **POST**, **PUT**, **PATCH**, and **DELETE** HTTP requests. You can add headers, form data, multipart files, and parameters with simple Python dictionaries, and access the response data in the same way. It's powered by :py:class:`httplib` and :py:class:`urllib3`, and it strives to be as elegant and approachable as possible. From 3d49eb40f80325c5a9a720797661287ab309a7b8 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 13 Nov 2011 01:17:27 -0500 Subject: [PATCH 02/13] sp --- docs/user/quickstart.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 4ead8755..cdbba6c9 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -39,7 +39,8 @@ We can read the content of the server's response:: >>> r.content '[{"repository":{"open_issues":0,"url":"https://github.com/... -Requests does its best to decode content from the server. Most unicode charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded. +Requests does its best to decode content from the server. Most unicode +charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded. Make a POST Request @@ -51,7 +52,8 @@ POST requests are equally simple:: Typically, you want to send some form-encoded data — much like an HTML form. -To do this, simply pass a dictionary to the `data` argument. Your dictionary of data will automatically be form-encoded when the request is made:: +To do this, simply pass a dictionary to the `data` argument. Your +dictionary of data will automatically be form-encoded when the request is made:: >>> payload = {'key1': 'value1', 'key2': 'value2'} >>> r = requests.post("http://httpbin.org/post", data=payload) @@ -114,7 +116,7 @@ Requests makes it simple to upload Multipart-encoded files:: { "origin": "179.13.100.4", "files": { - "hmm": "" + "report.xls": "" }, "form": {}, "url": "http://httpbin.org/post", @@ -254,7 +256,7 @@ Requests will automatically perform location redirection while using impodotent GitHub redirects all HTTP requests to HTTPS. Let's see what happens:: - >>> r = request.get('http://github.com') + >>> r = requests.get('http://github.com') >>> r.url 'https://github.com/' >>> r.status_code @@ -268,7 +270,7 @@ The :class:`Response.history` list contains a list of the If you're using GET, HEAD, or OPTIONS, you can disable redirection handling with the ``disable_redirects`` parameter:: - >>> r = request.get('http://github.com') + >>> r = requests.get('http://github.com') >>> r.status_code 301 >>> r.history @@ -276,7 +278,7 @@ handling with the ``disable_redirects`` parameter:: If you're using POST, PUT, PATCH, *&c*, you can also explicitly enable redirection as well:: - >>> r = request.post('http://github.com') + >>> r = requests.post('http://github.com') >>> r.url 'https://github.com/' >>> r.history From 45c9ecc82ad4ed99166b4aa6279cd52d80045333 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 13 Nov 2011 01:21:30 -0500 Subject: [PATCH 03/13] missing param in quick start --- 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 cdbba6c9..9039ded3 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -278,7 +278,7 @@ handling with the ``disable_redirects`` parameter:: If you're using POST, PUT, PATCH, *&c*, you can also explicitly enable redirection as well:: - >>> r = requests.post('http://github.com') + >>> r = requests.post('http://github.com', allow_redirects=True) >>> r.url 'https://github.com/' >>> r.history From e91fe9b2b8911bd0ca75ef64966c02292b5021eb Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 13 Nov 2011 01:21:58 -0500 Subject: [PATCH 04/13] stray note --- docs/user/quickstart.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 9039ded3..72f4b232 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -300,8 +300,6 @@ You can tell requests to stop waiting for a response after a given number of sec ``timeout`` only effects the connection process itself, not the downloading of the respone body. -Note - Errors and Exceptions --------------------- From 6b377cc919e8c079e5c4f2c752ccce3c2acc4e64 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 13 Nov 2011 01:24:29 -0500 Subject: [PATCH 05/13] grocer's apostrophe --- docs/user/advanced.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user/advanced.rst b/docs/user/advanced.rst index 70514ef7..0c26f2d3 100644 --- a/docs/user/advanced.rst +++ b/docs/user/advanced.rst @@ -71,7 +71,7 @@ You can override this default behavior with the ``prefetch`` parameter:: Configuring Requests -------------------- -Sometimes you may want to configure a request to customize it's behavior. To do +Sometimes you may want to configure a request to customize its behavior. To do this, you can pass in a ``config`` dictionary to a request or session. See the :ref:`Configuration API Docs ` to learn more. From d3cbf37352ec8462d07f27fbc0866cbf219dff1a Mon Sep 17 00:00:00 2001 From: Joseph McCullough Date: Mon, 14 Nov 2011 00:49:11 -0600 Subject: [PATCH 06/13] Removed closed issues from todo doc --- docs/dev/todo.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/dev/todo.rst b/docs/dev/todo.rst index 8a631d88..91c99749 100644 --- a/docs/dev/todo.rst +++ b/docs/dev/todo.rst @@ -7,9 +7,6 @@ Requests is under active development, and contributions are more than welcome! What Needs to be Done --------------------- -- OAuth Support (`#65 `_) - HTTP Cert Checking (`#30 `_) -- Removal of Poster (`#68 `_) - Python 3.x Support (`#70 `_) - Kerberos Support (`#47 `_) -- More Flexible Context Manager (`#69 `_) \ No newline at end of file From 588b6bbf8a3b03b4b12fe8e6a36ca923eb705c23 Mon Sep 17 00:00:00 2001 From: Joseph McCullough Date: Mon, 14 Nov 2011 01:09:12 -0600 Subject: [PATCH 07/13] Added OAuth reference to quickstart file --- docs/user/quickstart.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 72f4b232..542a5bc6 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -238,6 +238,11 @@ Making requests with Basic Auth is extremely simple:: >>> requests.get('https://api.github.com/user', auth=('user', 'pass')) +OAuth Authentication +-------------------- + +Miguel Araujo's `requests-oauth `_ project provides a simple interface for +establishing OAuth connections. Documentation and examples can be found on the requests-oauth `git repository `_. Digest Authentication --------------------- From a64a62088ad2598fd2c69b46216cf05cba381228 Mon Sep 17 00:00:00 2001 From: Peter Manser Date: Mon, 14 Nov 2011 09:44:43 +0100 Subject: [PATCH 08/13] Fixing status codes. Somehow these were wrong. --- docs/api.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index f77fc0ad..499ffd3c 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -95,13 +95,13 @@ Status Code Lookup :: >>> requests.codes['temporary_redirect'] - 301 + 307 >>> requests.codes.teapot - 416 + 418 >>> requests.codes['\o/'] - 416 + 200 Cookies ~~~~~~~ From f0edd4a3e0207d0ce447c9f09fc7e46d5cab118b Mon Sep 17 00:00:00 2001 From: Raymond Penners Date: Mon, 14 Nov 2011 10:04:07 +0100 Subject: [PATCH 09/13] Pass along timeout when following redirects (closes #263) --- requests/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/requests/models.py b/requests/models.py index 34de8005..bff73cbe 100644 --- a/requests/models.py +++ b/requests/models.py @@ -239,6 +239,7 @@ class Request(object): cookies=cookies, redirect=True, config=self.config, + timeout=self.timeout, _poolmanager=self._poolmanager ) From 35b0c5e16ea01a077357057fdd1b60fcfd64a73f Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 15 Nov 2011 10:59:39 +0800 Subject: [PATCH 10/13] fixed proxy --- requests/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index bff73cbe..da9abd3d 100644 --- a/requests/models.py +++ b/requests/models.py @@ -377,7 +377,7 @@ class Request(object): proxy = self.proxies.get(_p.scheme) if proxy: - conn = poolmanager.proxy_from_url(url) + conn = poolmanager.proxy_from_url(proxy) else: # Check to see if keep_alive is allowed. if self.config.get('keep_alive'): From 7c66e6f267016b84f9cbf55ebf10ee0219ea5562 Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 15 Nov 2011 15:53:38 +0800 Subject: [PATCH 11/13] fixed: 301 request does not use proxy. --- requests/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index da9abd3d..62d39a8a 100644 --- a/requests/models.py +++ b/requests/models.py @@ -240,7 +240,8 @@ class Request(object): redirect=True, config=self.config, timeout=self.timeout, - _poolmanager=self._poolmanager + _poolmanager=self._poolmanager, + proxies = self.proxies, ) request.send() From 4504953212816c4de0cd8177faf1270e42cb31f9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 15 Nov 2011 09:52:27 -0500 Subject: [PATCH 12/13] Only send URL path to servers Closes #256 --- requests/models.py | 49 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/requests/models.py b/requests/models.py index 62d39a8a..97237e77 100644 --- a/requests/models.py +++ b/requests/models.py @@ -11,7 +11,7 @@ import urllib import zlib from Cookie import SimpleCookie -from urlparse import urlparse, urlunparse, urljoin +from urlparse import urlparse, urlunparse, urljoin, urlsplit from datetime import datetime from .auth import dispatch as auth_dispatch @@ -181,7 +181,7 @@ class Request(object): if is_error: response.error = resp - response.url = self._build_url() + response.url = self.full_url return response @@ -281,8 +281,8 @@ class Request(object): else: return data, data - - def _build_url(self): + @property + def full_url(self): """Build the actual URL to use.""" if not self.url: @@ -300,15 +300,41 @@ class Request(object): path = path.encode('utf-8') path = urllib.quote(urllib.unquote(path)) - self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ])) + + url = str(urlunparse([ scheme, netloc, path, params, query, fragment ])) if self._enc_params: - if urlparse(self.url).query: - return '%s&%s' % (self.url, self._enc_params) + if urlparse(url).query: + return '%s&%s' % (url, self._enc_params) else: - return '%s?%s' % (self.url, self._enc_params) + return '%s?%s' % (url, self._enc_params) else: - return self.url + return url + + @property + def path_url(self): + """Build the path URL to use.""" + + url = [] + + p = urlsplit(self.full_url) + + # Proxies use full URLs. + if p.scheme in self.proxies: + return self.full_url + + path = p.path + if not path: + path = '/' + url.append(path) + + query = p.query + if query: + url.append('?') + url.append(query) + + return ''.join(url) + def send(self, anyway=False, prefetch=False): @@ -329,7 +355,7 @@ class Request(object): )) # Build the URL - url = self._build_url() + url = self.full_url # Nottin' on you. body = None @@ -406,10 +432,9 @@ class Request(object): try: # Send the request. - r = conn.urlopen( method=self.method, - url=url, + url=self.path_url, body=body, headers=self.headers, redirect=False, From b79dea97fd0d24bc1dbe52366565361c08675512 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 15 Nov 2011 09:56:21 -0500 Subject: [PATCH 13/13] v0.8.1 --- HISTORY.rst | 6 ++++++ requests/__init__.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 05ba2f49..8eecf875 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,12 @@ History ------- +0.8.1 (2011-11-15) +++++++++++++++++++ + +* URL Request path fix +* Proxy fix. +* Timeouts fix. 0.8.0 (2011-11-13) ++++++++++++++++++ diff --git a/requests/__init__.py b/requests/__init__.py index e3a9d2a0..b42d1210 100644 --- a/requests/__init__.py +++ b/requests/__init__.py @@ -15,8 +15,8 @@ requests """ __title__ = 'requests' -__version__ = '0.8.0' -__build__ = 0x000800 +__version__ = '0.8.1' +__build__ = 0x000801 __author__ = 'Kenneth Reitz' __license__ = 'ISC' __copyright__ = 'Copyright 2011 Kenneth Reitz'