Skip to content
Myr

Review changes to TooManyRedirect exception with response

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

authored by Ryan Munro · committed by Ryan Munro · parent 5a18066 · Browse files · 2 files+9 added−11 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+9 added−11 removed

  • other:+9 added−11 removed

2 files+9 added−11 removed

modified:requests/sessions.py+1 added-5 removed
108 unmodified lines
109 except (ChunkedEncodingError, ContentDecodingError, RuntimeError):110 resp.raw.read(decode_content=False)111112 if i >= self.max_redirects:113 raise TooManyRedirects(114 'Exceeded %s redirects.' % self.max_redirects,115 request=prepared_request,116 response=resp117 )113 raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects, response=resp)114115 # Release the connection back into the pool.116 resp.close()117
563 unmodified lines
modified:test_requests.py+8 added-6 removed
22 unmodified lines
23from requests.cookies import cookiejar_from_dict, morsel_to_cookie24from requests.exceptions import (ConnectionError, ConnectTimeout,25 InvalidSchema, InvalidURL, MissingSchema,26 ReadTimeout, Timeout, RetryError, TooManyRedirects)27from requests.models import PreparedRequest, DEFAULT_REDIRECT_LIMIT27from requests.models import PreparedRequest28from requests.structures import CaseInsensitiveDict29from requests.sessions import SessionRedirectMixin30from requests.models import urlencode31from requests.hooks import default_hooks
159 unmodified lines
191 def test_HTTP_302_TOO_MANY_REDIRECTS(self, httpbin):192 try:193 requests.get(httpbin('redirect', '50'))194 except TooManyRedirects as e:195 assert e.request is not None196 assert len(e.response.history) == DEFAULT_REDIRECT_LIMIT195 assert '/relative-redirect/20' in e.request.url196 assert e.request.url == e.response.url197 assert len(e.response.history) == 30198 else:198 assert False199 pytest.fail()200201 def test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS(self, httpbin):202 s = requests.session()203 s.max_redirects = 5204 try:205 s.get(httpbin('redirect', '50'))206 except TooManyRedirects as e:206 assert e.request is not None207 assert '/relative-redirect/45' in e.request.url208 assert e.request.url == e.response.url209 assert len(e.response.history) == 5210 else:209 assert False211 pytest.fail()212213 # def test_HTTP_302_ALLOW_REDIRECT_POST(self):214 # r = requests.post(httpbin('status', '302'), data={'some': 'data'})215 # self.assertEqual(r.status_code, 200)
1553 unmodified lines