Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TooManyRedirects not working in 2.4.0 #2207

Closed
ondrejsika opened this issue Sep 6, 2014 · 2 comments
Closed

TooManyRedirects not working in 2.4.0 #2207

ondrejsika opened this issue Sep 6, 2014 · 2 comments

Comments

@ondrejsika
Copy link

hi,

if i try page which has permanent redirect to it self, requests (2.4.0) cant raise TooManyRedirects exception. In 2.3.0 works fine.

try:

import requests
requests.get('http://www.dx.com/p/-268479')
@Lukasa
Copy link
Member

Lukasa commented Sep 6, 2014

Hurrah! As I predicted in #2095, our redirect cache has introduced a bug.

Specifically, if a website sets a permanent redirect to itself we will spin in an infinite loop forever on line 535 of sessions.py, trying to find the "real" url.

My proposed fix would be to change the logic where we add to the redirect cache (L138 of sessions.py) from this:

if resp.is_permanent_redirect:
    self.redirect_cache[req.url] = prepared_request.url

to this:

# Cache the URL unless it's a redirect to self.
if resp._is_permanent_redirect and req.url != prepared_request.url:
    self.redirect_cache[req.url] = prepared_request.url

@sigmavirus24
Copy link
Contributor

Don't be too happy @Lukasa. =P

@sigmavirus24 sigmavirus24 mentioned this issue Sep 7, 2014
Lukasa added a commit that referenced this issue Sep 9, 2014
ContinuousFunction pushed a commit to ContinuousFunction/requests that referenced this issue Nov 14, 2014
@Lukasa wrote the fix in psf#2207
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants