diff --git a/requests/defaults.py b/requests/defaults.py index c99786f0..49db114c 100644 --- a/requests/defaults.py +++ b/requests/defaults.py @@ -35,7 +35,7 @@ defaults['timeout'] = None defaults['max_redirects'] = 30 defaults['decode_unicode'] = True defaults['timeout_fallback'] = True -# defaults['keep_alive'] = True +defaults['keep_alive'] = True defaults['pool_connections'] = 10 defaults['pool_maxsize'] = 1 defaults['max_retries'] = 0 diff --git a/requests/models.py b/requests/models.py index 3b711cf5..1c4d5758 100644 --- a/requests/models.py +++ b/requests/models.py @@ -20,6 +20,7 @@ from .hooks import dispatch_hook from .structures import CaseInsensitiveDict from .status_codes import codes from .packages.urllib3.exceptions import MaxRetryError +from .packages.urllib3 import connectionpool from .exceptions import ( Timeout, URLRequired, TooManyRedirects, HTTPError, ConnectionError) from .utils import ( @@ -352,7 +353,11 @@ class Request(object): self.__dict__.update(r.__dict__) - conn = self._poolmanager.connection_from_url(url) + if self.config.get('keep_alive'): + conn = self._poolmanager.connection_from_url(url) + else: + conn = connectionpool.connection_from_url(url) + print 'NO CONNECTION FOR YOU1' if not self.sent or anyway: @@ -373,7 +378,7 @@ class Request(object): self.headers['Cookie'] = cookie_header try: - # Create the connection. + # Send the request. r = conn.urlopen( method=self.method, url=url, @@ -385,6 +390,7 @@ class Request(object): decode_content=False, retries=self.config.get('max_retries', 0) ) + except MaxRetryError, e: if not self.config.get('safe_mode', False): raise ConnectionError(e) diff --git a/test_requests.py b/test_requests.py index 300779e4..8b0f7c7a 100755 --- a/test_requests.py +++ b/test_requests.py @@ -57,6 +57,8 @@ class RequestsTestSuite(unittest.TestCase): def tearDown(self): """Teardown.""" # self.httpbin.kill() + pass + def test_entry_points(self): @@ -551,8 +553,5 @@ class RequestsTestSuite(unittest.TestCase): assert r.content == None - - - if __name__ == '__main__': unittest.main()