Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress warnings about lack of cert verification in a requests HTTPS call?

I would like to disable the warning about a lack of certificate verification in a HTTPS call using requests.

The question has been asked in the past, leading to answers about disabling a relevant request logging or the urllib3 SSL warning.

This used to work in the past (I remember successfully silencing the warnings) but seems not to work anymore?

I put together the two solutions which worked so far:

Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
>>> import requests
>>> import requests.packages
>>> import urllib3
>>> urllib3.disable_warnings()
>>> requests.packages.urllib3.disable_warnings()
>>> requests.get('https://www.google.com', verify=False)
/usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: 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
  InsecureRequestWarning)
<Response [200]>

Is there another (current) solution to silence these warnings?

like image 930
WoJ Avatar asked Feb 13 '18 12:02

WoJ


People also ask

How do I disable the security certificate check in Python requests?

Method 1: Passing verify=False to request methodAlong with the URL also pass the verify=False parameter to the method in order to disable the security checks.

What is insecure request warning?

These InsecureRequestWarning warning messages show up when a request is made to an HTTPS URL without certificate verification enabled.


2 Answers

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

There are two different ways to do this, both of these work. You will have to add this to your imports

from requests.packages.urllib3.exceptions import InsecureRequestWarning
like image 155
Arnav Chawla Avatar answered Oct 20 '22 14:10

Arnav Chawla


Instead of using
requests.packages.urllib3.disable_warnings()

Use
requests.urllib3.disable_warnings()

like image 21
fyqc Avatar answered Oct 20 '22 13:10

fyqc