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?
import urllib3
, thenurllib3.__file__
produces/usr/lib/python3/dist-packages/urllib3/__init__.py
?.disable_warnings()
call only runswarnings.simplefilter('ignore', urllib3.exceptions.HTTPWarning)
(andInsecureRequestWarning
is an indirect subclass ofHTTPWarning
, so is also ignored).urllib3.__file__
produces/usr/lib/python3/dist-packages/urllib3/__init__.py
import warnings; [(w[0], w[2]) for w in warnings.filters]
consists of?requests.packages.urllib3
is just an alias forurllib3
now; you can see this when you echorequests.packages.urllib3.__file__
in your interpreter, it'll produce/usr/lib/python3/dist-packages/urllib3/__init__.py
)