Skip to content
Myr

HTTP Basic recursion. Fixes #31

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 62931b6 · Browse files · 2 files+39 added−3 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+39 added−3 removed

  • other:+39 added−3 removed

2 files+39 added−3 removed

modified:requests/core.py+32 added-3 removed
53 unmodified lines
5455 return urllib2.Request.get_method(self)565758class _HTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):59 # from mercurial6061 def __init__(self, *args, **kwargs):62 urllib2.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)63 self.retried_req = None6465 def reset_retry_count(self):66 # Python 2.6.5 will call this on 401 or 407 errors and thus loop67 # forever. We disable reset_retry_count completely and reset in68 # http_error_auth_reqed instead.69 pass7071 def http_error_auth_reqed(self, auth_header, host, req, headers):72 # Reset the retry counter once for each request.73 if req is not self.retried_req:74 self.retried_req = req75 self.retried = 076 return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed(77 self, auth_header, host, req, headers)787980class Request(object):81 """The :class:`Request` object. It carries out all functionality of82 Requests. Recommended interface is with the Requests functions.83 """
90 unmodified lines
174 return opener.open175176 def _build_response(self, resp):177 """Build internal Response object from given response."""178 if isinstance(resp, HTTPError):179 # print resp.__dict__180 pass181182 self.response.status_code = getattr(resp, 'code', None)158 self.response.headers = getattr(resp.info(), 'dict', None)159 self.response.content = resp.read()183184 try:185 self.response.headers = getattr(resp.info(), 'dict', None)186 self.response.content = resp.read()187 except AttributeError, why:188 pass189190 if self.response.headers.get('content-encoding', None) == 'gzip':191 try:192 self.response.content = zlib.decompress(self.response.content, 16+zlib.MAX_WBITS)193 except zlib.error:
265 unmodified lines
459 :param handler: (optional) basic || digest || proxy_basic || proxy_digest460 """461462 _handlers = {434 'basic': urllib2.HTTPBasicAuthHandler,463 'basic': _HTTPBasicAuthHandler,464 'digest': urllib2.HTTPDigestAuthHandler,465 'proxy_basic': urllib2.ProxyBasicAuthHandler,466 'proxy_digest': urllib2.ProxyDigestAuthHandler467 }
123 unmodified lines
modified:test_requests.py+7 added
147 unmodified lines
148 requests.get('http://google.com', params={'føø': 'føø'})149 requests.get('http://google.com', params={'foo': u'foo'})150 requests.get('http://google.com/ø', params={'foo': u'foo'})151152 def test_httpauth_recursion(self):153 conv_auth = ('requeststest', 'bad_password')154155 r = requests.get('https://convore.com/api/account/verify.json', auth=conv_auth)156 self.assertEquals(r.status_code, 401)157 print r.__dict__158159160if __name__ == '__main__':161 unittest.main()