Skip to content
Myr

add 'max_retries' configuration

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent c48f0d9 · Browse files · 2 files+23 added−48 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+23 added−48 removed

  • other:+23 added−48 removed

2 files+23 added−48 removed

modified:requests/defaults.py+1 added
36 unmodified lines
37defaults['timeout_fallback'] = True38# defaults['keep_alive'] = True39defaults['pool_connections'] = 1040defaults['pool_maxsize'] = 141defaults['max_retries'] = 0
modified:requests/models.py+22 added-48 removed
12 unmodified lines
1314from urlparse import urlparse, urlunparse, urljoin15from datetime import datetime161718from .auth import dispatch as auth_dispatch19from .hooks import dispatch_hook20from .structures import CaseInsensitiveDict21from .status_codes import codes21from .exceptions import Timeout, URLRequired, TooManyRedirects, HTTPError2222from .packages.urllib3.exceptions import MaxRetryError23from .exceptions import (24 Timeout, URLRequired, TooManyRedirects, HTTPError, ConnectionError)25from .utils import (26 dict_from_cookiejar, get_unicode_from_response,27 stream_decode_response_unicode, decode_gzip, stream_decode_gzip)28
101 unmodified lines
130 def __repr__(self):131 return '<Request [%s]>' % (self.method)132133132 # def _get_opener(self):133 # """Creates appropriate opener object for urllib2."""134135 # _handlers = []136137 # if self.cookies is not None:138 # _handlers.append(urllib2.HTTPCookieProcessor(self.cookies))139140 # if self.proxies:141 # _handlers.append(urllib2.ProxyHandler(self.proxies))142143 # _handlers.append(HTTPRedirectHandler)144145 # if not _handlers:146 # return urllib2.urlopen147148 # if self.data or self.files:149 # _handlers.extend(get_handlers())150151 # opener = urllib2.build_opener(*_handlers)152153 # if self.headers:154 # # Allow default headers in the opener to be overloaded155 # normal_keys = [k.capitalize() for k in self.headers]156 # for key, val in opener.addheaders[:]:157 # if key not in normal_keys:158 # continue159 # # Remove it, we have a value to take its place160 # opener.addheaders.remove((key, val))161162 # return opener.open163164134 def _build_response(self, resp, is_error=False):135 """Build internal :class:`Response <Response>` object136 from given response.137 """
49 unmodified lines
187 ('location' in r.headers) and188 ((r.status_code is codes.see_other) or (self.allow_redirects))189 ):190222 # r.raw.close()223191 if not len(history) < self.config.get('max_redirects'):192 raise TooManyRedirects()193194 history.append(r)
173 unmodified lines
368369 # Attach Cookie header to request.370 self.headers['Cookie'] = cookie_header371372 try:405 # Create the connection.406 r = conn.urlopen(407 method=self.method,408 url=url,409 body=body,410 headers=self.headers,411 redirect=False,412 assert_same_host=False,413 preload_content=False,414 decode_content=False415 )373 # Create the connection.374 r = conn.urlopen(375 method=self.method,376 url=url,377 body=body,378 headers=self.headers,379 redirect=False,380 assert_same_host=False,381 preload_content=False,382 decode_content=False,383 retries=self.config.get('max_retries', 0)384 )385 except MaxRetryError, e:386 if self.config.get('safe_mode', False):387 pass388 raise ConnectionError(e)389390391 self._build_response(r)392393 # Response manipulation hook.394 self.response = dispatch_hook('response', self.hooks, self.response)
152 unmodified lines