spyoungtech / grequests

Requests + Gevent = <3
https://pypi.python.org/pypi/grequests
BSD 2-Clause "Simplified" License
4.49k stars 331 forks source link

Response and request both contains different urls than response due to redirection. #35

Closed bhanuvrat closed 8 years ago

bhanuvrat commented 11 years ago

The returned response objects contain the redirected url, and I am unable to find the one that I requested for. How do I find which returned object corresponds to which requested url?

In [31]: urls = [                             
    'http://www.heroku.com',
    'http://python-tablib.org',
    'http://httpbin.org',
    'http://python-requests.org',
    'http://kennethreitz.com'
]

In [32]: rs = (grequests.get(u) for u in urls)

In [33]: for i in grequests.imap(rs):         
    print i, i.url
   ....:     
<Response [200]> https://www.heroku.com/
<Response [200]> http://docs.python-tablib.org/en/latest/
<Response [200]> http://httpbin.org/
<Response [200]> http://docs.python-requests.org/en/latest/
<Response [200]> https://medium.com/@kennethreitz/collections/

neither response.url, nor response.request.url give the requested url.

In [35]: rs = (grequests.get(u) for u in urls)

In [36]: for i in grequests.imap(rs):
    print i, i.request.url
   ....:     
<Response [200]> https://www.heroku.com/
<Response [200]> http://docs.python-tablib.org/en/latest/
<Response [200]> http://httpbin.org/
<Response [200]> http://docs.python-requests.org/en/latest/
<Response [200]> https://medium.com/@kennethreitz/collections/