Python SSLError - Any way to Hide Warning

Viewed 7010

I am wokirng on windows and with python3. I used requests module to get to a web page with this code-

requests.get('https://github.com/')

Then i got the SSLError [SSL: CERTIFICATE VERIFY FAILED ] error. Then i turned off the switch for SSL certificates check with verify=False.

import requests
requests.get('https://github.com/', verify=False)

And now it is browsing the site but returns a warning.

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 847
    InsecureRequestWarning)
InsecureRequestWarning: Unverified HTTPS request is being made. Adding 
certificate verification is strongly advised. See: 
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
<Response [200]>

Now i am working with a script and i don't want to show this warning to user.I got a way to hide warning but i am not sure how to use it.

warnings.simplefilter("ignore")

But this ignores all warnings and i just want to hide this 'InsecureRequestWarning' particularly. Please guide me how to do this.

1 Answers

So i got the solution to hide the warning. Here is what i did.

import warnings
from requests.packages.urllib3.exceptions import InsecureRequestWarning

warnings.simplefilter('ignore',InsecureRequestWarning)
requests.get('https://github.com/',verify=False)

And this thing solved my problem.

Related