Answer the question
In order to leave comments, you need to log in
How to pass an additional argument to a callback function?
Hello.
There is something like this python code:
def response_handler(response, **kwargs):
print(response.url)
urls = [
{"id":1, "url":"http://httpbin.org/delay/1"},
{"id":2, "url":"http://httpbin.org/delay/1"}
]
results = grequests.map((grequests.get(u["url"], callback=response_handler) for u in urls))
<lambda>() got an unexpected keyword argument 'timeout'
Answer the question
In order to leave comments, you need to log in
def response_handler(response, url_id):
print(response.url)
results = grequests.map(
(grequests.get(u["url"], callback=lambda r, uid=u['id'], **kw: response_handler(r, uid)) for u in urls))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question