How to disable security certificate checks for requests in Python
Last Updated :
29 Oct, 2022
In this article, we will discuss how to disable security certificate checks for requests in Python.
In Python, the requests module is used to send HTTP requests of a particular method to a specified URL. This request returns a response object that includes response data such as encoding, status, content, etc. But whenever we perform operations like get, post, delete, etc.
We will get SSLCertVerificationError i.e., SSL:Certificate_Verify_Failed self-signed certificate. To get rid of this error there are two ways to disable the security certificate checks. They are
- Passing verify=False to request method.
- Use Session.verify=False
Method 1: Passing verify=False to request method
The requests module has various methods like get, post, delete, request, etc. Each of these methods accepts an URL for which we send an HTTP request. Along with the URL also pass the verify=False parameter to the method in order to disable the security checks.
Python3
import requests
# sending a get http request to specified url
response = requests.request(
"GET", "https://www.geeksforgeeks.org/", verify=False)
# response data
print(response.text)
print(response)
Output:
<Response [200]>

Explanation: By passing verify=False to the request method we disabled the security certificate check and made the program error-free to execute. But this approach will throw warnings as shown in the output picture. This can be avoided by using urlib3.disable_warnings method.
Handle the abovewarning with requests.packages.urllib3.disable_warnings() method
The above warning that occurred while using verify=False in the request method can be suppressed by using the urllib3.disable_warnings method.
Python3
import requests
from urllib3.exceptions import InsecureRequestWarning
# Suppress the warnings from urllib3
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
# sending a get http request to specified url
response = requests.get("https://www.geeksforgeeks.org/",
verify=False)
# response data
print(response)
Output:
<Response [200]>
Method 2: Use Session.verify=False
The alternate way of disabling the security check is using the Session present in requests module. We can declare the Session.verify=False instead of passing verify=True as parameter. Let's look into the sample code so that one will get the clear picture of using Session.
Python3
import requests
# creating Session object and
# declaring the verify variable to False
session = requests.Session()
session.verify = False
# sending a get http request to specified url
response = requests.get("https://www.geeksforgeeks.org/")
# response data
print(response.text)
Output

Similar Reads
SSL Certificate Verification - Python requests Requests verifies SSL certificates for HTTPS requests, just like a web browser. SSL Certificates are small data files that digitally bind a cryptographic key to an organization's details. Often, a website with a SSL certificate is termed as secure website. By default, SSL verification is enabled, an
2 min read
How To Enable or Disable CGI Scripts in Apache? This article will guide you on how to enable or disable CGI scripts in Apache. Configuring CGI scripts in Apache is a crucial aspect of managing dynamic content generation on web servers. The Common Gateway Interface (CGI) provides a standardized protocol for executing programs, allowing websites to
4 min read
How to Fix Python Requests SSLError? The Python requests library is widely used for making HTTP requests simply and elegantly. However, when working with SSL (Secure Sockets Layer) connections, users may occasionally encounter an SSLError. This error typically arises due to issues with SSL certificates, which are crucial for establishi
5 min read
How to Install and use SSL Certificate In Python A secure Socket Layer (SSL) Certificate is a Digital certificate that can be used for the authentication of a website and it helps to establish an encrypted connection between the user and server. SSL is a secure layer that creates an encrypted link between a web server and a web browser. SSL keeps
2 min read
Authentication using Python requests Authentication refers to giving a user permissions to access a particular resource. Since, everyone can't be allowed to access data from every URL, one would require authentication primarily. To achieve this authentication, typically one provides authentication data through Authorization header or a
2 min read