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:

The easiest way to do Web Scraping

Get HTML from any page with a simple API call. We handle proxy rotation, browser identities, automatic retries, CAPTCHAs, JavaScript rendering, etc automatically for you


Try ProxiesAPI for free

curl "http://api.proxiesapi.com/?key=API_KEY&url=https://example.com"

<!doctype html>
<html>
<head>
    <title>Example Domain</title>
    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
...

X

Don't leave just yet!

Enter your email below to claim your free API key: