Script works ok when receiving a HTTP 200. However as soon as I get an exception I receive a error. I know the website does not have a valid SSL cert installed and I've tried to requests.exceptions.RequestException to catch anything, but still throws me errors. I'll also get exceptions such as proxy error come up now and then, and requests.exceptions.RequestException would not catch it. I have also tried, under try: request.raise_for_status() and that still throws an error. Code is as follows:
def verify_ssl(proxy_info, target):
print('Attempting to verify SSL Cert on %s:443' % target)
if proxy_info == None:
response = requests.get('https://%s' % target)
if proxy_info != None:
response = requests.get('https://%s' % target, proxies=proxy_info)
try:
response
except requests.exceptions.SSLError as g:
print('SSL Verification Error %s' % g)
return ('Successfully Verified SSL Cert: HTTP 200 received.\n')
Debug throws me this:
Traceback (most recent call last):
File "c:\Users\appleta\Desktop\ping.py", line 69, in <module>
ssl_result = verify_ssl(proxy_info, target)
File "c:\Users\appleta\Desktop\ping.py", line 37, in verify_ssl
response = requests.get('https://%s' % target)
File "C:\Python34\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\Python34\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "C:\Python34\lib\site-packages\requests\adapters.py", line 511, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='blabla.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)'),))