Python grequests返回';无';即使在使用异常处理程序后也要键入

Python grequests返回';无';即使在使用异常处理程序后也要键入,python,grequests,Python,Grequests,我正在使用grequests模块进行异步请求。测试时,以下代码根据超时值显示异常: >>> grequests.map((grequests.get('http://httpbin.org/delay/1',timeout=0.6),),exception_handler=exception_handler) failed: http://httpbin.org/delay/1 [<Response [200]>] >>> grequests

我正在使用grequests模块进行异步请求。测试时,以下代码根据超时值显示异常:

>>> grequests.map((grequests.get('http://httpbin.org/delay/1',timeout=0.6),),exception_handler=exception_handler)
failed:  http://httpbin.org/delay/1 

[<Response [200]>]
>>> grequests.map((grequests.get('http://httpbin.org/delay/1', timeout=0.001),),exception_handler=exception_handler)
failed:  http://httpbin.org/delay/1 

[None]

我猜原因是您只更改了
r
url
,但没有更改它的
超时时间。
timeout
的值存储在
self.kwargs

根据报告:

timeout
的值存储在
self.kwargs
中。当您更改
exception\u handler
中存储在
self.url
中的
url
值时,它没有改变

>>> def exception_handler(r,e):
        print('failed: ',r.url,'\n')
        #changing the url just for doing sth
        r.url = 'http://httpbin.org/status/200'
        res = r.send().response 
        return res
""" Asynchronous request.
    Accept same parameters as ``Session.request`` and some additional:
    :param session: Session which will do request
    :param callback: Callback called on response.
                     Same as passing ``hooks={'response': callback}``
    """
    def __init__(self, method, url, **kwargs):
        #: Request method
        self.method = method
        #: URL to request
        self.url = url
        #: Associated ``Session``
        self.session = kwargs.pop('session', None)
        if self.session is None:
            self.session = Session()

        callback = kwargs.pop('callback', None)
        if callback:
            kwargs['hooks'] = {'response': callback}

        #: The rest arguments for ``Session.request``
        self.kwargs = kwargs
        #: Resulting ``Response``
        self.response = None