Skip to content
Myr

Merge pull request #2972 from munro/master

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

Return request & response with TooManyRedirects

authored by Cory Benfield · committed by Cory Benfield · parents 8b92d99, 56a1b55 · Browse files · 2 files+26 added−2 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+26 added−2 removed

  • other:+26 added−2 removed

2 files+26 added−2 removed

modified:requests/sessions.py+1 added-1 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('Exceeded %s redirects.' % self.max_redirects)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+25 added-1 removed
21 unmodified lines
22 )23from requests.cookies import cookiejar_from_dict, morsel_to_cookie24from requests.exceptions import (ConnectionError, ConnectTimeout,25 InvalidSchema, InvalidURL, MissingSchema,26 ReadTimeout, Timeout, RetryError)26 ReadTimeout, Timeout, RetryError, TooManyRedirects)27from requests.models import PreparedRequest28from requests.structures import CaseInsensitiveDict29from requests.sessions import SessionRedirectMixin30from requests.models import urlencode
156 unmodified lines
187 assert r.status_code == 200188 assert r.history[0].status_code == 302189 assert r.history[0].is_redirect190191 def test_HTTP_302_TOO_MANY_REDIRECTS(self, httpbin):192 try:193 requests.get(httpbin('relative-redirect', '50'))194 except TooManyRedirects as e:195 url = httpbin('relative-redirect', '20')196 assert e.request.url == url197 assert e.response.url == url198 assert len(e.response.history) == 30199 else:200 pytest.fail('Expected redirect to raise TooManyRedirects but it did not')201202 def test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS(self, httpbin):203 s = requests.session()204 s.max_redirects = 5205 try:206 s.get(httpbin('relative-redirect', '50'))207 except TooManyRedirects as e:208 url = httpbin('relative-redirect', '45')209 assert e.request.url == url210 assert e.response.url == url211 assert len(e.response.history) == 5212 else:213 pytest.fail('Expected custom max number of redirects to be respected but was not')214215 # def test_HTTP_302_ALLOW_REDIRECT_POST(self):216 # r = requests.post(httpbin('status', '302'), data={'some': 'data'})217 # self.assertEqual(r.status_code, 200)218
1552 unmodified lines