首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grequests忽略ssl错误

grequests忽略ssl错误
EN

Stack Overflow用户
提问于 2019-11-20 02:51:00
回答 1查看 303关注 0票数 3

我想传递一个参数来忽略一大组GET的SSL错误。在请求包中,你可以传递verfiy=false参数。对于grequest,我没有看到任何类似的东西。如果有更好的方案或方向,我是开放的。

代码语言:javascript
复制
urls = [
    'https://www.heroku.com',
    'https://tablib.org',
    'https://httpbin.org',
    'https://python-requests.org',
    'https://kennethreitz.com'
]

rs = (grequests.get(u) for u in urls)

grequests.map(rs)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-26 05:05:11

代码语言:javascript
复制
#to raise exception
def exception_handler(request, exception):
    return f"Request failed: {exception}"

# to fully skip error/warning
#def exception_handler(request, exception):
#    pass or do something

urls = [
    'https://www.heroku.com',
    'https://tablib.org',
    'https://httpbin.org',
    'https://python-requests.org',
    'https://kennethreitz.com'
]

rs = (grequests.get(u) for u in urls)

grequests.map(rs, exception_handler=exception_handler)

#also you can do a trick with requests library (ignore certificates issue):
>>> def exception_handler(request, exception):
...     return dir(request)
...
>>> rs = (grequests.get(u) for u in url)
>>> grequests.map(rs, exception_handler=exception_handler)
[['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', 
'__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', 
'__str__', '__subclasshook__', '__weakref__', 'exception', 'kwargs', 
'method', 'response', 'send', 'session', 'traceback', 'url'], 
<Response[200]>]
# we can take request.url and put it in requests.get(request.url, 
# verify=False)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58940986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档