From bc5cc0dc92ae0b6edc356c90637a0d64e1d5042b Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Fri, 9 Mar 2012 17:26:57 -0500 Subject: [PATCH 01/25] potentially fixes #338 This attempts to fix an issue where encoding of a string might fail when the encoding is set to some unknown format. Here we attempt to catch the LookupException and subsequently blindly encode the string one final time. That is we call str() over response.content without specifying an encoding. This may still fail in certain cases but does properly handle the case of #338 by returning the expected string. --- requests/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requests/models.py b/requests/models.py index 753e83ab..4bccb1e3 100644 --- a/requests/models.py +++ b/requests/models.py @@ -788,6 +788,9 @@ class Response(object): # Decode unicode from given encoding. try: content = str(self.content, encoding, errors='replace') + except LookupError: + # try blindly encoding + content = str(self.content, errors='replace') except (UnicodeError, TypeError): pass From 83a9f2c7407347a4e1e148e2a1bea4b47e1543c0 Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Sun, 11 Mar 2012 22:22:29 -0400 Subject: [PATCH 02/25] explicating the cause of LookupError with a better comment --- requests/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index 4bccb1e3..fa06948a 100644 --- a/requests/models.py +++ b/requests/models.py @@ -789,7 +789,10 @@ class Response(object): try: content = str(self.content, encoding, errors='replace') except LookupError: - # try blindly encoding + # A LookupError is raised if the encoding was not found which could + # indicate a misspelling or similar mistake. + # + # So we try blindly encoding. content = str(self.content, errors='replace') except (UnicodeError, TypeError): pass From 06f048e5074da7b02ce640a3531a58956f656de4 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 12 Mar 2012 20:46:23 -0700 Subject: [PATCH 03/25] lies. --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index e79211cd..e8ec2378 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012 Kenneth Reitz. +Copyright (c) 2012 Josh Ourisman. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -10,4 +10,4 @@ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. From 8d34538f4c702657698c1784ef8e5face7f400e5 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 12 Mar 2012 20:54:02 -0700 Subject: [PATCH 04/25] further lies. --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index e8ec2378..e79211cd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012 Josh Ourisman. +Copyright (c) 2012 Kenneth Reitz. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -10,4 +10,4 @@ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file From 17170a2ca7672c6b05282c45f91430a32d8521fc Mon Sep 17 00:00:00 2001 From: Idan Gazit Date: Tue, 13 Mar 2012 12:59:33 -0700 Subject: [PATCH 05/25] Merge branch 'develop', remote-tracking branch 'upstream/develop' into develop From 84d9a1b577b69bcf5af18c232990b5a9c7d4dec3 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 13 Mar 2012 16:39:51 -0700 Subject: [PATCH 06/25] dict_to_sequence --- requests/sessions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/requests/sessions.py b/requests/sessions.py index 87320d6e..7ed8fa5e 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -16,6 +16,15 @@ from .utils import header_expand from .packages.urllib3.poolmanager import PoolManager +def dict_to_sequence(d): + """Returns an internal sequence dictionary update.""" + + if hasattr(d, 'items'): + d = d.items() + + return d + + def merge_kwargs(local_kwarg, default_kwarg): """Merges kwarg dictionaries. From 0dd6c4020535bbd45f25580dae5037b77cc1b707 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 13 Mar 2012 16:42:16 -0700 Subject: [PATCH 07/25] dict sequence --- requests/sessions.py | 3 +++ requests/utils.py | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/requests/sessions.py b/requests/sessions.py index 7ed8fa5e..04d7d5dd 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -31,6 +31,9 @@ def merge_kwargs(local_kwarg, default_kwarg): If a local key in the dictionary is set to None, it will be removed. """ + + + if default_kwarg is None: return local_kwarg diff --git a/requests/utils.py b/requests/utils.py index 6952a996..4c94c661 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -14,7 +14,6 @@ import codecs import os import random import re -import traceback import zlib from netrc import netrc, NetrcParseError @@ -26,6 +25,15 @@ from .compat import basestring, bytes, str NETRC_FILES = ('.netrc', '_netrc') +def dict_to_sequence(d): + """Returns an internal sequence dictionary update.""" + + if hasattr(d, 'items'): + d = d.items() + + return d + + def get_netrc_auth(url): """Returns the Requests tuple auth for a given url from netrc.""" From 29309201b66c19445719600297edbac74c1a4264 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 13 Mar 2012 16:44:45 -0700 Subject: [PATCH 08/25] remove cruft --- requests/sessions.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/requests/sessions.py b/requests/sessions.py index 04d7d5dd..87320d6e 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -16,24 +16,12 @@ from .utils import header_expand from .packages.urllib3.poolmanager import PoolManager -def dict_to_sequence(d): - """Returns an internal sequence dictionary update.""" - - if hasattr(d, 'items'): - d = d.items() - - return d - - def merge_kwargs(local_kwarg, default_kwarg): """Merges kwarg dictionaries. If a local key in the dictionary is set to None, it will be removed. """ - - - if default_kwarg is None: return local_kwarg From eae641485bf46081f0f36726716f27034e814d50 Mon Sep 17 00:00:00 2001 From: Idan Gazit Date: Tue, 13 Mar 2012 17:04:26 -0700 Subject: [PATCH 09/25] Remove unused import --- requests/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requests/auth.py b/requests/auth.py index 2e2bebcb..385dd27d 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -11,7 +11,7 @@ import time import hashlib from base64 import b64encode -from .compat import urlparse, str, bytes +from .compat import urlparse, str from .utils import randombytes, parse_dict_header From 8f8062723ae75b25c6f7b1dead7a52e611734302 Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Tue, 13 Mar 2012 20:10:32 -0400 Subject: [PATCH 10/25] removing unused import --- requests/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/requests/utils.py b/requests/utils.py index 6952a996..9b78cefc 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -14,7 +14,6 @@ import codecs import os import random import re -import traceback import zlib from netrc import netrc, NetrcParseError From 82e69de44f222f9af0ef0888ae78995298efbd92 Mon Sep 17 00:00:00 2001 From: "chadnickbok@gmail.com" Date: Wed, 14 Mar 2012 15:57:30 -0700 Subject: [PATCH 11/25] Exposed key_file and cert_file in requests, to support https client certificates. --- requests/api.py | 2 ++ requests/models.py | 12 +++++++++++- requests/sessions.py | 12 ++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/requests/api.py b/requests/api.py index b079eedd..3c79646b 100644 --- a/requests/api.py +++ b/requests/api.py @@ -33,6 +33,8 @@ def request(method, url, **kwargs): :param config: (optional) A configuration dictionary. :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided. :param prefetch: (optional) if ``True``, the response content will be immediately downloaded. + :param key_file: (optional) ssl client key file. + :param cert_file: (optional) ssl client cert file. """ s = kwargs.pop('session') if 'session' in kwargs else sessions.session() diff --git a/requests/models.py b/requests/models.py index 753e83ab..d827042b 100644 --- a/requests/models.py +++ b/requests/models.py @@ -63,7 +63,9 @@ class Request(object): config=None, _poolmanager=None, verify=None, - session=None): + session=None, + key_file=None, + cert_file=None): #: Dictionary of configurations for this request. self.config = dict(config or []) @@ -143,6 +145,10 @@ class Request(object): #: SSL Verification. self.verify = verify + #: SSL Certificate + self.key_file = key_file + self.cert_file = cert_file + if headers: headers = CaseInsensitiveDict(self.headers) else: @@ -507,6 +513,10 @@ class Request(object): conn.cert_reqs = 'CERT_NONE' conn.ca_certs = None + if self.key_file and self.cert_file: + conn.key_file = self.key_file + conn.cert_file = self.cert_file + if not self.sent or anyway: if self.cookies: diff --git a/requests/sessions.py b/requests/sessions.py index 04d7d5dd..90fbacf0 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -77,7 +77,9 @@ class Session(object): params=None, config=None, prefetch=False, - verify=True): + verify=True, + key_file=None, + cert_file=None): self.headers = headers or {} self.cookies = cookies or {} @@ -89,6 +91,8 @@ class Session(object): self.config = config or {} self.prefetch = prefetch self.verify = verify + self.key_file = key_file + self.cert_file = cert_file for (k, v) in list(defaults.items()): self.config.setdefault(k, v) @@ -131,7 +135,9 @@ class Session(object): return_response=True, config=None, prefetch=False, - verify=None): + verify=None, + key_file=None, + cert_file=None): """Constructs and sends a :class:`Request `. Returns :class:`Response ` object. @@ -188,6 +194,8 @@ class Session(object): proxies=proxies, config=config, verify=verify, + key_file=key_file, + cert_file=cert_file, _poolmanager=self.poolmanager ) From fc618aa78a63d372e160a42f1589dbb738ab16a2 Mon Sep 17 00:00:00 2001 From: "chadnickbok@gmail.com" Date: Wed, 14 Mar 2012 17:15:29 -0700 Subject: [PATCH 12/25] Updated Requests api to accept a 'cert' argument. This argument can be either a string, containing the path to a pem-formatted key and certificate chain, or a tuple of (cert, key). When supplied a tuple, the values are paths to an SSL certificate chain file and key, respectively. --- requests/api.py | 3 +-- requests/models.py | 18 ++++++++++-------- requests/sessions.py | 15 ++++++--------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/requests/api.py b/requests/api.py index 3c79646b..3188a2d0 100644 --- a/requests/api.py +++ b/requests/api.py @@ -33,8 +33,7 @@ def request(method, url, **kwargs): :param config: (optional) A configuration dictionary. :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided. :param prefetch: (optional) if ``True``, the response content will be immediately downloaded. - :param key_file: (optional) ssl client key file. - :param cert_file: (optional) ssl client cert file. + :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. """ s = kwargs.pop('session') if 'session' in kwargs else sessions.session() diff --git a/requests/models.py b/requests/models.py index d827042b..717e36fd 100644 --- a/requests/models.py +++ b/requests/models.py @@ -64,8 +64,7 @@ class Request(object): _poolmanager=None, verify=None, session=None, - key_file=None, - cert_file=None): + cert=None): #: Dictionary of configurations for this request. self.config = dict(config or []) @@ -146,8 +145,7 @@ class Request(object): self.verify = verify #: SSL Certificate - self.key_file = key_file - self.cert_file = cert_file + self.cert = cert if headers: headers = CaseInsensitiveDict(self.headers) @@ -273,7 +271,8 @@ class Request(object): _poolmanager=self._poolmanager, proxies=self.proxies, verify=self.verify, - session=self.session + session=self.session, + cert=self.cert ) request.send() @@ -513,9 +512,12 @@ class Request(object): conn.cert_reqs = 'CERT_NONE' conn.ca_certs = None - if self.key_file and self.cert_file: - conn.key_file = self.key_file - conn.cert_file = self.cert_file + if self.cert: + if type(self.cert) is tuple: + conn.cert_file = self.cert[0] + conn.key_file = self.cert[1] + else: + conn.cert_file = self.cert if not self.sent or anyway: diff --git a/requests/sessions.py b/requests/sessions.py index 90fbacf0..61b97490 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -64,7 +64,7 @@ class Session(object): __attrs__ = [ 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks', - 'params', 'config', 'verify'] + 'params', 'config', 'verify', 'cert'] def __init__(self, @@ -78,8 +78,7 @@ class Session(object): config=None, prefetch=False, verify=True, - key_file=None, - cert_file=None): + cert=None): self.headers = headers or {} self.cookies = cookies or {} @@ -91,8 +90,7 @@ class Session(object): self.config = config or {} self.prefetch = prefetch self.verify = verify - self.key_file = key_file - self.cert_file = cert_file + self.cert = cert for (k, v) in list(defaults.items()): self.config.setdefault(k, v) @@ -136,8 +134,7 @@ class Session(object): config=None, prefetch=False, verify=None, - key_file=None, - cert_file=None): + cert=None): """Constructs and sends a :class:`Request `. Returns :class:`Response ` object. @@ -157,6 +154,7 @@ class Session(object): :param config: (optional) A configuration dictionary. :param prefetch: (optional) if ``True``, the response content will be immediately downloaded. :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided. + :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. """ method = str(method).upper() @@ -194,8 +192,7 @@ class Session(object): proxies=proxies, config=config, verify=verify, - key_file=key_file, - cert_file=cert_file, + cert=cert, _poolmanager=self.poolmanager ) From 4677ba5cd9ba5a1aed98b9b60d3e1431a0ca2cb9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 14 Mar 2012 20:29:30 -0400 Subject: [PATCH 13/25] only verify private cert when verity is true --- requests/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requests/models.py b/requests/models.py index 717e36fd..d301a001 100644 --- a/requests/models.py +++ b/requests/models.py @@ -512,8 +512,8 @@ class Request(object): conn.cert_reqs = 'CERT_NONE' conn.ca_certs = None - if self.cert: - if type(self.cert) is tuple: + if self.cert and self.verify: + if len(self.cert) == 2: conn.cert_file = self.cert[0] conn.key_file = self.cert[1] else: From 1c73ec22e93c15d584cab3c14578e03e6313bad4 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 14 Mar 2012 20:30:03 -0400 Subject: [PATCH 14/25] Nick Chadwick --- AUTHORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 9cfa7db0..c3d5005a 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -88,3 +88,4 @@ Patches and Suggestions - Chris Dary - Danver Braganza - Max Countryman +- Nick Chadwick From 0c0bab3ad0bdf15204aa2b0f426304a6dd655da0 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 14 Mar 2012 20:31:43 -0400 Subject: [PATCH 15/25] v0.11.0 --- HISTORY.rst | 6 ++++++ requests/__init__.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index c05a71e4..d43585c4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,12 @@ History ------- +0.11.0 (2012-03-14) ++++++++++++++++++++ + +* Private SSL Certificate support +* + 0.10.8 (2012-03-09) +++++++++++++++++++ diff --git a/requests/__init__.py b/requests/__init__.py index 73d81f67..138e26e3 100644 --- a/requests/__init__.py +++ b/requests/__init__.py @@ -15,8 +15,8 @@ requests """ __title__ = 'requests' -__version__ = '0.10.8' -__build__ = 0x001008 +__version__ = '0.11.0' +__build__ = 0x001100 __author__ = 'Kenneth Reitz' __license__ = 'ISC' __copyright__ = 'Copyright 2012 Kenneth Reitz' From ee861f42873ed3b19dd382c3d6fb9e0d5a7521cf Mon Sep 17 00:00:00 2001 From: Pinkerton Date: Wed, 14 Mar 2012 19:54:06 -0700 Subject: [PATCH 16/25] Fix issue #484 --- requests/packages/oreos/monkeys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requests/packages/oreos/monkeys.py b/requests/packages/oreos/monkeys.py index 72ce68d3..2cf90163 100644 --- a/requests/packages/oreos/monkeys.py +++ b/requests/packages/oreos/monkeys.py @@ -255,7 +255,7 @@ class CookieError(Exception): # _RFC2965Forbidden = "[]:{}=" _LegalChars = ( string.ascii_letters + string.digits + - "!#$%&'*+-.^_`|~_" + _RFC2965Forbidden ) + "!#$%&'*+-.^_`|~_@" + _RFC2965Forbidden ) _Translator = { '\000' : '\\000', '\001' : '\\001', '\002' : '\\002', '\003' : '\\003', '\004' : '\\004', '\005' : '\\005', From d6827a37d00f3fcdac56e5dd978400e9ec1a7371 Mon Sep 17 00:00:00 2001 From: Michael Newman Date: Thu, 15 Mar 2012 14:41:45 -0400 Subject: [PATCH 17/25] Excluding select from the monkey patching that gevent does to allow select.poll and requests.async in the same project Fix for issue #487, including a regression test that checks the existence of select.poll before and after loading requests.async. --- requests/async.py | 2 +- tests/test_requests_async.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) mode change 100644 => 100755 tests/test_requests_async.py diff --git a/requests/async.py b/requests/async.py index f2dad694..f12cf268 100644 --- a/requests/async.py +++ b/requests/async.py @@ -17,7 +17,7 @@ except ImportError: raise RuntimeError('Gevent is required for requests.async.') # Monkey-patch. -curious_george.patch_all(thread=False) +curious_george.patch_all(thread=False, select=False) from . import api diff --git a/tests/test_requests_async.py b/tests/test_requests_async.py old mode 100644 new mode 100755 index 2d37bbb0..1d282616 --- a/tests/test_requests_async.py +++ b/tests/test_requests_async.py @@ -8,6 +8,9 @@ sys.path.insert(0, os.path.abspath('..')) import sys import unittest +import select +has_poll = hasattr(select, "poll") + from requests import async import envoy @@ -57,6 +60,9 @@ class RequestsTestSuiteUsingAsyncApi(RequestsTestSuite): async.map async.send + def test_select_poll(self): + """Test to make sure we don't overwrite the poll""" + self.assertEqual(hasattr(select, "poll"), has_poll) if __name__ == '__main__': unittest.main() From a094ad8f312165b96d889cb4d24eb5954556a0db Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Thu, 15 Mar 2012 22:05:08 -0300 Subject: [PATCH 18/25] fixing link to AUTHORS in README --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ad88b42d..7ea6ab64 100644 --- a/README.rst +++ b/README.rst @@ -73,4 +73,4 @@ Contribute #. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS_. .. _`the repository`: http://github.com/kennethreitz/requests -.. _AUTHORS: http://github.com/kennethreitz/requests/blob/master/AUTHORS +.. _AUTHORS: https://github.com/kennethreitz/requests/blob/develop/AUTHORS.rst From f2172922c51932bf2155a9fb4d7be6475002f32e Mon Sep 17 00:00:00 2001 From: Jonathan Drosdeck Date: Sun, 18 Mar 2012 15:37:46 -0400 Subject: [PATCH 19/25] Add quickstart doc and example for passing parameters in a GET request --- AUTHORS.rst | 1 + docs/user/quickstart.rst | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index c3d5005a..243033fb 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -89,3 +89,4 @@ Patches and Suggestions - Danver Braganza - Max Countryman - Nick Chadwick +- Jonathan Drosdeck \ No newline at end of file diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 3202ee67..70ec5f13 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -30,6 +30,32 @@ Let's get GitHub's public timeline :: Now, we have a :class:`Response` object called ``r``. We can get all the information we need from this. +Typically, you want to send some sort of data in the urls query string. +To do this, simply pass a dictionary to the `params` argument. Your +dictionary of data will automatically be encoded when the request is made:: + + >>> payload = {'key1': 'value1', 'key2': 'value2'} + >>> r = requests.get("http://httpbin.org/get", params=payload) + >>> print r.text + { + "origin": "179.13.100.4", + "args": { + "key2": "value2", + "key1": "value1" + }, + "url": "http://httpbin.org/get", + "headers": { + "Connections": "keep-alive", + "Content-Length": "", + "Accept-Encoding": "identity, deflate, compress, gzip", + "Accept": "*/*", + "User-Agent": "python-requests/0.11.0", + "Host": httpbin.org", + "Content-Type": "" + }, + } + + Response Content ---------------- From 7b68c124d549853a1045cbeb5a16461799279780 Mon Sep 17 00:00:00 2001 From: Ian Danforth Date: Sun, 18 Mar 2012 18:09:58 -0700 Subject: [PATCH 20/25] Sphinx throws an error if you don't escape ** in **kwargs --- requests/api.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/requests/api.py b/requests/api.py index 3188a2d0..e0bf346c 100644 --- a/requests/api.py +++ b/requests/api.py @@ -45,7 +45,7 @@ def get(url, **kwargs): """Sends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ kwargs.setdefault('allow_redirects', True) @@ -56,7 +56,7 @@ def options(url, **kwargs): """Sends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ kwargs.setdefault('allow_redirects', True) @@ -67,7 +67,7 @@ def head(url, **kwargs): """Sends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ kwargs.setdefault('allow_redirects', False) @@ -79,7 +79,7 @@ def post(url, data=None, **kwargs): :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ return request('post', url, data=data, **kwargs) @@ -90,7 +90,7 @@ def put(url, data=None, **kwargs): :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ return request('put', url, data=data, **kwargs) @@ -101,7 +101,7 @@ def patch(url, data=None, **kwargs): :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ return request('patch', url, data=data, **kwargs) @@ -111,7 +111,7 @@ def delete(url, **kwargs): """Sends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ return request('delete', url, **kwargs) From 44277441d6bc55254a54d827fcae9cb025371465 Mon Sep 17 00:00:00 2001 From: Ian Danforth Date: Sun, 18 Mar 2012 18:11:15 -0700 Subject: [PATCH 21/25] Sphinx throws an error if you don't escape ** in **kwargs --- requests/sessions.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/requests/sessions.py b/requests/sessions.py index f66529e8..0aeeef1e 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -218,7 +218,7 @@ class Session(object): """Sends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ kwargs.setdefault('allow_redirects', True) @@ -229,7 +229,7 @@ class Session(object): """Sends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ kwargs.setdefault('allow_redirects', True) @@ -240,7 +240,7 @@ class Session(object): """Sends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ kwargs.setdefault('allow_redirects', False) @@ -252,7 +252,7 @@ class Session(object): :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ return self.request('post', url, data=data, **kwargs) @@ -263,7 +263,7 @@ class Session(object): :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ return self.request('put', url, data=data, **kwargs) @@ -274,7 +274,7 @@ class Session(object): :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ return self.request('patch', url, data=data, **kwargs) @@ -284,7 +284,7 @@ class Session(object): """Sends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. - :param **kwargs: Optional arguments that ``request`` takes. + :param \*\*kwargs: Optional arguments that ``request`` takes. """ return self.request('delete', url, **kwargs) From e65f52aae4e347ecfbf1010745e899519ad5c6e6 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 18 Mar 2012 22:02:43 -0400 Subject: [PATCH 22/25] remove debian packaging warning it's up to date now --- docs/community/out-there.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/community/out-there.rst b/docs/community/out-there.rst index 553c7444..5ef090f3 100644 --- a/docs/community/out-there.rst +++ b/docs/community/out-there.rst @@ -50,9 +50,6 @@ Requests is available installed as a Debian package! Debian Etch Ubuntu, since O $ apt-get install python-requests -Unfortunately, the most recent version available is v0.5.0. If you're on the -Debian Python Package team, I'd love an update of that :) - Fedora and RedHat ----------------- From 3c2f52d6813f181fc53b01f67ca25ef1fae0f321 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Sun, 18 Mar 2012 23:06:42 -0300 Subject: [PATCH 23/25] Fixes issues #496 by having Response.ok catch all Requests exceptions. --- requests/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index ac1a9e2f..27ad7809 100644 --- a/requests/models.py +++ b/requests/models.py @@ -660,7 +660,7 @@ class Response(object): def ok(self): try: self.raise_for_status() - except HTTPError: + except RequestException: return False return True From 76bf523a1f5d20de70e7ff5ddf2a681bea8987f8 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 18 Mar 2012 22:15:05 -0400 Subject: [PATCH 24/25] Merge #491 --- AUTHORS.rst | 3 ++- HISTORY.rst | 2 +- requests/models.py | 34 +--------------------------------- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 243033fb..f3816222 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -89,4 +89,5 @@ Patches and Suggestions - Danver Braganza - Max Countryman - Nick Chadwick -- Jonathan Drosdeck \ No newline at end of file +- Jonathan Drosdeck +- Jiri Machalek diff --git a/HISTORY.rst b/HISTORY.rst index d43585c4..6604fbe0 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -5,7 +5,7 @@ History +++++++++++++++++++ * Private SSL Certificate support -* +* Remove select.poll from Gevent monkeypatching 0.10.8 (2012-03-09) +++++++++++++++++++ diff --git a/requests/models.py b/requests/models.py index ac1a9e2f..0c74afad 100644 --- a/requests/models.py +++ b/requests/models.py @@ -683,39 +683,7 @@ class Response(object): yield chunk self._content_consumed = True - def generate_chunked(): - resp = self.raw._original_response - fp = resp.fp - if resp.chunk_left is not None: - pending_bytes = resp.chunk_left - while pending_bytes: - chunk = fp.read(min(chunk_size, pending_bytes)) - pending_bytes -= len(chunk) - yield chunk - fp.read(2) # throw away crlf - while 1: - #XXX correct line size? (httplib has 64kb, seems insane) - pending_bytes = fp.readline(40).strip() - if not len(pending_bytes): - # No content, like a HEAD request. Break out. - break - pending_bytes = int(pending_bytes, 16) - if pending_bytes == 0: - break - while pending_bytes: - chunk = fp.read(min(chunk_size, pending_bytes)) - pending_bytes -= len(chunk) - yield chunk - fp.read(2) # throw away crlf - self._content_consumed = True - fp.close() - - if getattr(getattr(self.raw, '_original_response', None), 'chunked', False): - gen = generate_chunked() - else: - gen = generate() - - gen = stream_untransfer(gen, self) + gen = stream_untransfer(generate(), self) if decode_unicode: gen = stream_decode_response_unicode(gen, self) From eab2ab9faa0c61a899692978a0b67f657290931e Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 18 Mar 2012 22:19:48 -0400 Subject: [PATCH 25/25] Steve Pulec --- AUTHORS.rst | 1 + HISTORY.rst | 2 ++ 2 files changed, 3 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index f3816222..1db8611d 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -91,3 +91,4 @@ Patches and Suggestions - Nick Chadwick - Jonathan Drosdeck - Jiri Machalek +- Steve Pulec diff --git a/HISTORY.rst b/HISTORY.rst index 6604fbe0..99472503 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,6 +6,8 @@ History * Private SSL Certificate support * Remove select.poll from Gevent monkeypatching +* Remove redundant generator for chunked transfer encoding +* Fix: Response.ok raises Timeout Exception in safe_mode 0.10.8 (2012-03-09) +++++++++++++++++++