Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grequests ignore ssl errors

I would like to pass an arg to ignore SSL errors for a large group of GET's. In the requests package you can pass the verfiy=false argument. I do not see anything like this for grequests. If there is a better package or direction I'm open.


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)
like image 724
Brian Avatar asked Feb 26 '26 02:02

Brian


1 Answers

#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)
like image 176
ChantOfSpirit Avatar answered Mar 03 '26 02:03

ChantOfSpirit