Disable "InsecureRequestWarning: Unverified HTTPS request" warning in Python Requests
Sending HTTP requests to WEB-server with self-signed certificate from Python Requests library may display in terminal some warnings. The most popular warning is: «InsecureRequestWarning: Unverified HTTPS request». Don't worry, it's just a warning. But if you want disable it, follow this tutorial.
Output example with self-signed certificate:
/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1048: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.0.150'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
warnings.warn(
Request example, which display this warning:
user@localhost:~$ python
Python 3.11.2 (main, May 2 2024, 11:59:08) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> r = requests.get(url='https://192.168.0.150', verify=False)
/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1048: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.0.150'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
warnings.warn(
>>> print(r.status_code)
200
>>>
To fix this issue you need to call "disable_warnings()" module in urllib3 package:
user@localhost:~$ python
Python 3.11.2 (main, May 2 2024, 11:59:08) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.packages.urllib3.disable_warnings()
>>> r = requests.get(url='https://192.168.0.150', verify=False)
>>> print(r.status_code)
200
>>>
Support me on Patreon
#http #http-requests #https #python #ssl #ssl-certificate #troubleshooting