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
Provenance
- Commit
6a8a480- Tree
cc1da1a- Author
Ryan Munro <ryan@submersible.io>- Committer
Ryan Munro <ryan@submersible.io>- Parent
5a18066
2 files changed+9 added−11 removed
modified:requests/sessions.py+1 added-5 removed
108 unmodified lines109 except (ChunkedEncodingError, ContentDecodingError, RuntimeError):110 resp.raw.read(decode_content=False)111 112 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)114 115 # Release the connection back into the pool.116 resp.close()117 563 unmodified linesmodified:test_requests.py+8 added-6 removed
22 unmodified lines23 from requests.cookies import cookiejar_from_dict, morsel_to_cookie24 from requests.exceptions import (ConnectionError, ConnectTimeout,25 InvalidSchema, InvalidURL, MissingSchema,26 ReadTimeout, Timeout, RetryError, TooManyRedirects)27-from requests.models import PreparedRequest, DEFAULT_REDIRECT_LIMIT27+from requests.models import PreparedRequest28 from requests.structures import CaseInsensitiveDict29 from requests.sessions import SessionRedirectMixin30 from requests.models import urlencode31 from requests.hooks import default_hooks159 unmodified lines191 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()200 201 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()212 213 # 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