When making network requests using the requests library, you may sometimes encounter SSL certificate errors, especially in a test environment. This article will show you how to ignore SSL certificate errors via the verify=False parameter and provide a way to disable warnings.

Ignore certificate verification

SSL certificate verification can be easily bypassed by using the requests.get() method and setting the verify=False parameter. Here is a simple code example:

If you set verify=False, requests will skip verifying the server's SSL certificate; although this will allow the request to succeed, it may lead to data being attacked by a man-in-the-middle or other security risks because the legitimacy of the server cannot be confirmed. Therefore, urllib3 will issue InsecureRequestWarning to remind developers that the request is insecure and data transmission may be tampered with or intercepted.

import requests

# Ignore SSL certificate errors
response = requests.get('https://example.com', verify=False)

print(response.status_code)

Disable security warnings

To prevent security warnings, you can use urllib3 to disable the warnings:

Why use urllib3

Because the requests library is built on urllib3, requests is essentially a high-level encapsulation of urllib3.

from requests.packages.urllib3.exceptions import InsecureRequestWarning

# Disable InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)