python requests post ignore certificate

How to ignore certificate while doing POST requests using Python requests library?

Python requests library is a very useful tool for making HTTP requests in Python. Sometimes we might come across situations where the SSL certificate of the target website is not trusted by our system or the certificate is expired. In such scenarios, Python requests might throw errors like SSL certificate verification failed. In this blog, we will see how to ignore the SSL certificate verification while making POST requests using Python requests.

Method 1: Ignore SSL Verification using verify parameter

The verify parameter of the requests.post() function is set to True by default. This default value means that Python requests will try to verify the SSL certificate of the target website. If the SSL certificate is not valid, it will throw an error. To ignore SSL verification while making POST requests, we can set the verify parameter to False.


import requests

url = 'https://example.com/api'
payload = {'key1': 'value1', 'key2': 'value2'}

response = requests.post(url, data=payload, verify=False)

Method 2: Ignore SSL Verification using Session object

We can also use a Session object to make POST requests with SSL verification disabled. When we create a Session object, it uses the default parameters for all the subsequent requests made using that object. We can set the verify parameter to False for the Session object to disable SSL verification.


import requests

url = 'https://example.com/api'
payload = {'key1': 'value1', 'key2': 'value2'}

session = requests.Session()
session.verify = False

response = session.post(url, data=payload)

Method 3: Ignore SSL Verification using Environment Variable

Another way to ignore SSL verification while making POST requests using Python requests is by setting the REQUESTS_CA_BUNDLE environment variable to an empty string. This method is useful when we don't want to modify the code and want to disable SSL verification globally for all requests made using Python requests.


import os
import requests

os.environ['REQUESTS_CA_BUNDLE'] = ''
url = 'https://example.com/api'
payload = {'key1': 'value1', 'key2': 'value2'}

response = requests.post(url, data=payload)

These are the three methods we can use to ignore SSL certificate verification while making POST requests using Python requests library. However, it is recommended to verify the SSL certificate of the target website for security reasons. Disabling SSL verification should only be done if we have a valid reason for doing so.