GithubHelp home page GithubHelp logo

Tracking chained redirection about requests HOT 8 CLOSED

psf avatar psf commented on July 21, 2024
Tracking chained redirection

from requests.

Comments (8)

jgorset avatar jgorset commented on July 21, 2024

I'm +1 on this, though I suggest the entire response object is made available so one can inspect their headers retrospectively.

>> response = requests.get('http://example.org/redirect.html')
>> response.redirects
>> [<Response [301]>, <Response [301]>, <Response [301]>]

from requests.

esaurito avatar esaurito commented on July 21, 2024

I agree with you jgorset. Is better to have the entire response object

from requests.

kennethreitz avatar kennethreitz commented on July 21, 2024

This is a good idea. I think a good place for would be Response.history as a property.

>>> r = requests.get('http://301x3')
>>> r.history
[<Response [301]>, <Response [301]>, <Response [301]>]

These response objects wouldn't contain any history themselves.

At the moment, all of the redirection is coming strait from urllib2 transparently. We'd have to write a custom HTTPRedirectHandler.

Reference: http://diveintopython.org/http_web_services/redirects.html

from requests.

jgorset avatar jgorset commented on July 21, 2024

Yes, Response.history would be perfect.

from requests.

chmullig avatar chmullig commented on July 21, 2024

+1 on this. I wrote a gnarly RedirectHandler for a work project that did something similar. It's not horrible, but not much fun either.

from requests.

kennethreitz avatar kennethreitz commented on July 21, 2024

v0.4.0 was just released, which implements this. Enjoy :)

from requests.

jgorset avatar jgorset commented on July 21, 2024

Nice work, @kennethreitz!

from requests.

esaurito avatar esaurito commented on July 21, 2024

Thanks @kennethreitz!

from requests.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.