Making HTTP Requests in Python Without SSL Verification

Feb 3, 2024 ยท 2 min read

When making HTTP requests in Python using the popular requests library, SSL certificate verification is enabled by default for security. However, sometimes you may want to disable SSL verification, like when testing locally or connecting to a server with a self-signed certificate.

Here are a few methods to make Python requests without SSL verification.

Disable SSL Verification for a Session

You can disable SSL verification for a requests session by setting verify to False:

import requests

session = requests.Session()
session.verify = False
response = session.get("https://example.com") 

This will disable verification for all requests made with this session.

Disable Per Request

To disable SSL verification for a single request, pass in verify=False:

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

Provide a Custom SSL Context

For more control, you can create a custom SSL context that doesn't verify certificates:

import ssl
import requests

context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE

response = requests.get("https://example.com", ssl_context=context)

Ignore SSL Warnings

You can also suppress the SSL warnings if you just want to ignore them:

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

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)  

response = requests.get("https://example.com")

The best option depends on your specific use case. Just remember that disabling SSL verification reduces security, so only do it when necessary.

Browse by tags:

Browse by language:

Tired of getting blocked while scraping the web?

ProxiesAPI handles headless browsers and rotates proxies for you.
Get access to 1,000 free API credits, no credit card required!