spyoungtech / grequests

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

Redirect not being followed before callback #110

Closed spyoungtech closed 7 years ago

spyoungtech commented 7 years ago

I'm not sure if this is an expected behavior or not, but I'm suffering from a problem where my callback is receiving the initial 302 response from the request, rather than the subsequent 200 response I expect.

Given the following examples using requests and grequests I would expect the output to be the same, however they are not.

With requests

response = requests.get('http://example.com/search/value')
print(response.status_code)
print(response.url)
print(responose.history)
for hist in response.history:
    print(hist.url)

Output

200
'http://example.com/search/NoResults'
[<Response [302]>]
'http://example.com/search/value'

With grequests


def my_callback(response, *args, **kwargs):
    print(response.status_code)
    print(response.url)
    print(response.history)
    for hist in response.history:
        print(hist.url)

request_list = [grequests.get('http://example.com/search/value', callback=my_callback)]
grequests.map(request_list)

Output

302
'http://example.com/search/value'
[]
spyoungtech commented 7 years ago

Actually realized my error was result of raising an exception in my callback, which triggered the exception handler to return a value and, as a result, preventing the subsequent response from happening