Tag Archives: InsecureRequestWarning error

Python: How to Disable InsecureRequestWarning error

Python Disable InsecureRequestWarning error

Send HTTPS requests using Python 3 requests. When SSL authentication is turned off (verify = false):

import requests
response = requests.get(url='http://127.0.0.1:12345/test', verify=False)

Error Messages:

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

Solution:

#python3
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

#python2
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

PS: as shown below, disable_warnings() will disable all warning types.

def disable_warnings(category=exceptions.HTTPWarning):
    """
    Helper for quickly disabling all urllib3 warnings.
    """
    warnings.simplefilter("ignore", category)