python requests library ignore ssl

Python Requests Library: Ignoring SSL Certificates

If you are using Python's Requests library to make HTTP requests to a website with a self-signed SSL certificate or an expired SSL certificate, you may receive an SSL error. To bypass this error and proceed with the request, you can tell Requests to ignore SSL certificate verification.

Using verify=False

The easiest way to ignore SSL certificate verification is by passing verify=False parameter when making the request.

import requests

response = requests.get("https://example.com", verify=False)
print(response.text)

Disabling Warnings

If you don't want to see the warning messages that Requests generates when you bypass SSL certificate verification, you can disable the warnings.

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

response = requests.get("https://example.com", verify=False)
print(response.text)

Adding Custom Certificates

If you are using a self-signed certificate, you can add the certificate to the trusted certificates list in your system or pass it directly to the Requests library.

import requests

cert = "/path/to/cert.pem"
response = requests.get("https://example.com", cert=cert)
print(response.text)