Python 如何处理GRequests中的错误?

Python 如何处理GRequests中的错误?,python,python-requests,grequests,Python,Python Requests,Grequests,我有这个密码 #!/usr/bin/python import grequests urls = [ 'http://google.com', 'http://doesnotexists.tld' ] def do_something(response, **kwargs): print response.text async_list = [] for u in urls: action_item = grequests.get(u, timeout=10,

我有这个密码

#!/usr/bin/python

import grequests

urls = [
'http://google.com',
'http://doesnotexists.tld'
]


def do_something(response, **kwargs):
        print response.text

async_list = []

for u in urls:
    action_item = grequests.get(u, timeout=10, hooks = {'response' : do_something})
    async_list.append(action_item)

grequests.map(async_list,size=10)
如何处理错误而不获取常见的Python错误消息?

例如,对于不存在的域,它打印出“未找到”。

从pypi安装的
grequests
似乎不包括异常处理。但github的版本实现了这一功能:

def map(requests, stream=False, size=None, exception_handler=None)
因此,您应该克隆grequests或从github下载grequests.py并使用该版本。您可以使用pip直接安装该版本:

pip install git+https://github.com/kennethreitz/grequests.git

如果要查找异常处理示例,可以查看存储库中的test.py

最新版本的grequests已经解决了这个问题-

您可以使用try和except,这里描述的类似方法仍然不起作用
try:grequests.map(async_list,size=10),但ConnectionError为e:print e
Um。什么不起作用?如果您不知道输出的内容,请不要打印它!(将
打印e
替换为
通过