grequests 响应的顺序是否与请求的顺序相同? [英] Are grequests responses in the same order as the requests?

查看:52
本文介绍了grequests 响应的顺序是否与请求的顺序相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 grequests 从使用相同 url 但不同参数的网站异步下载数据.

例如

unsent_requests = []for params in params: # 假设 params 是一个包含不同参数或查询字符串的列表unsent_requests.append(grequests.get(url = url, params = param))响应 = grequests.map(未发送)

我怎么可能知道响应中的哪个响应属于 unsent_requests 中的哪个请求?还是响应与未发送请求的顺序相同?

PS:response.url 没有给出任何线索,因为返回了一个完全不同的 url.

解决方案

响应与请求的顺序相同,如用法示例:

<预><代码>>>>请求 = [... grequests.get('http://httpbin.org/delay/1', timeout=0.001),... grequests.get('http://fakedomain/'),... grequests.get('http://httpbin.org/status/500')]>>>grequests.map(reqs, exception_handler=exception_handler)请求失败请求失败[无,无,<响应 [500]>]

I am using the grequests to asynchronously download data from a website using the same url but different parameters.

For example,

unsent_requests = []
for param in params: # assume params is a list containing different parameters or query strings
    unsent_requests.append(grequests.get(url = url, params = param))

responses = grequests.map(unsent)

How can I possibly get to know which response from responses belongs to which request from unsent_requests? Or are the responses in the same order as the unsent requests?

PS: response.url does not give any clue because a completely different url returns.

解决方案

Responses are in the same order as the requests, as shown in the usage example:

>>> reqs = [
...    grequests.get('http://httpbin.org/delay/1', timeout=0.001),
...    grequests.get('http://fakedomain/'),
...    grequests.get('http://httpbin.org/status/500')]
>>> grequests.map(reqs, exception_handler=exception_handler)
Request failed
Request failed
[None, None, <Response [500]>]

这篇关于grequests 响应的顺序是否与请求的顺序相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆