Python 完全禁用grequests日志记录

Python 完全禁用grequests日志记录,python,python-requests,grequests,Python,Python Requests,Grequests,如何抑制从grequests获取的以下调试错误消息 Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 327, in run result = self._run(*self.args, **self.kwargs) File "/usr/local/lib/python2.7/dist-packages/greques

如何抑制从
grequests
获取的以下调试错误消息

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 327, in run
    result = self._run(*self.args, **self.kwargs)
  File "/usr/local/lib/python2.7/dist-packages/grequests.py", line 71, in send
    self.url, **merged_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 456, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 559, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 384, in send
    raise Timeout(e, request=request)
Timeout: HTTPSConnectionPool(host='itunes.apple.com', port=443): Read timed out.
<Greenlet at 0x7ff0c8165910: <bound method AsyncRequest.send of <grequests.AsyncRequest object at 0x7ff0c880b8d0>>(stream=False)> failed with Timeout
错误发生在以下位置:

rs = (grequests.get(url, headers=headers, cookies=cookies, proxies=proxies, timeout=timeout) for url in urls)
res_items = grequests.map(rs) # <-- this command produces all the errors
rs=(对于url中的url,grequests.get(url,headers=headers,cookies=cookies,proxies=proxies,timeout=timeout)

res_items=grequests.map(rs)#为此,您需要做三件事:

(1) 确保已安装最新版本的
grequests

sudo pip install git+https://github.com/kennethreitz/grequests.git
(2) 为
grequests.map
函数提供一个处理程序:

def exception_handler(request, exception):
    pass # suppress errors on grequests.map

res_items = grequests.map(rs, exception_handler=exception_handler)
(3) 抑制
urllib3
警告:

import urllib3
urllib3.disable_warnings()
logging.captureWarnings(True)
现在,应该不会再有来自
grequests
的警告了

import urllib3
urllib3.disable_warnings()
logging.captureWarnings(True)