Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Security and hardening

Python prints InsecureRequestWarning: Unverified HTTPS request

Your error

InsecureRequestWarning: Unverified HTTPS request is being made to host 'example.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings1 more line it can show

Fix it fast

Most common cause, 1 of 3

Your requests call or Session sets verify=False

Delete verify=False so requests checks the certificate again.

Fix
import requests

session = requests.Session()
session.verify = "/etc/ssl/certs/internal-ca.pem"   # or delete the line for public sites
resp = session.get("https://api.internal.example/health")

# or for every requests call in the process:
# export REQUESTS_CA_BUNDLE=/etc/ssl/certs/internal-ca.pem
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

InsecureRequestWarning: Unverified HTTPS request is being made to host means urllib3 sent an HTTPS request with certificate checking turned off, usually through verify=False in requests or cert_reqs="CERT_NONE" in urllib3. Find the call with python -W "error:Unverified HTTPS request", then remove the switch and point verify or ca_certs at the right CA bundle. Applies to urllib3 2.8 and requests 2.34.

  • Applies to urllib3 2.8.0, requests 2.34.2, Python 3.12 and later
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Turn this one warning into an exception for a single run. The traceback then ends at the exact line that made the unverified request: your own code with verify=False is cause 1, a direct urllib3 pool is cause 2, and a frame inside another package's folder is cause 3.

Run this first
python -W "error:Unverified HTTPS request" app.py

Then find the line you see in this list and open its fix:

  1. 1Your requests call or Session sets verify=FalseThe last frame in your own code shows verify=False on requests.get, requests.post or a Session
  2. 2A urllib3 PoolManager is built with cert_reqs="CERT_NONE"The traceback ends at a urllib3.PoolManager or HTTPSConnectionPool request, and the grep finds CERT_NONE
  3. 3A CLI or SDK was told to skip TLS checks, often to get past a proxyThe traceback ends inside another package's site-packages folder, often on a network with a TLS-inspecting proxy

What does the error look like?

  • InsecureRequestWarning: Unverified HTTPS request is being made to host 'example.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  • connectionpool.py:1129: InsecureRequestWarning: Unverified HTTPS request is being made to host 'example.com'.

Cause 1 of 3

Your requests call or Session sets verify=False

You seeThe last frame in your own code shows verify=False on requests.get, requests.post or a Session

Check

urllib3 raises InsecureRequestWarning for each HTTPS request made without certificate verification, and requests passes verify=False straight down to it. The requests docs warn that this setting accepts any certificate, ignores hostname mismatches and expired certificates, and leaves the app open to man-in-the-middle attacks.

Check
grep -rn "verify=False\|verify = False" --include=*.py .

Fix

Delete verify=False so requests checks the certificate again. If the server uses an internal or self-signed CA, give requests that CA's bundle file instead of turning checks off, either per call, per Session, or through REQUESTS_CA_BUNDLE.

Fix
import requests

session = requests.Session()
session.verify = "/etc/ssl/certs/internal-ca.pem"   # or delete the line for public sites
resp = session.get("https://api.internal.example/health")

# or for every requests call in the process:
# export REQUESTS_CA_BUNDLE=/etc/ssl/certs/internal-ca.pem

Verify

Run the same -W command again. The script finishes with no exception, which means every request was verified.

Verify
python -W "error:Unverified HTTPS request" app.py

Confirmed by requests.readthedocs.io

Did this fix it?

Cause 2 of 3

A urllib3 PoolManager is built with cert_reqs="CERT_NONE"

You seeThe traceback ends at a urllib3.PoolManager or HTTPSConnectionPool request, and the grep finds CERT_NONE

Check

Since urllib3 1.25, HTTPS connections verify certificates by default (cert_reqs="CERT_REQUIRED"). A pool created with cert_reqs="CERT_NONE" switches that off, and the user guide calls it highly recommended to leave verification on. Every request from such a pool produces the warning.

Check
grep -rn "CERT_NONE" --include=*.py .

Fix

Create the pool with verification on and a CA bundle. certifi provides Mozilla's root bundle for public sites; use your own CA file for internal ones.

Fix
import certifi
import urllib3

http = urllib3.PoolManager(
    cert_reqs="CERT_REQUIRED",
    ca_certs=certifi.where(),
)
resp = http.request("GET", "https://example.com")

Verify

The request succeeds without the warning. A host with a bad certificate now raises SSLError instead of passing silently.

Verify
python -W "error:Unverified HTTPS request" app.py

Confirmed by urllib3.readthedocs.io

Did this fix it?

Cause 3 of 3

A CLI or SDK was told to skip TLS checks, often to get past a proxy

You seeThe traceback ends inside another package's site-packages folder, often on a network with a TLS-inspecting proxy

Check

The warning also appears when a tool you did not write turns verification off through its own setting, a common workaround on networks whose proxy re-signs HTTPS traffic with a company CA. The request is still unverified, and urllib3 still warns, because the switch only hides the real problem: the tool does not trust the proxy's CA.

Check
gcloud config list

Fix

Turn the tool's skip-verification setting off again and give it the proxy's CA certificate. For the Google Cloud CLI that is the core/custom_ca_certs_file property; tools built on requests read REQUESTS_CA_BUNDLE.

Fix
gcloud config set core/custom_ca_certs_file /etc/ssl/certs/corp-proxy-ca.pem
# tools built on requests:
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/corp-proxy-ca.pem

Verify

Run the tool's command again. It completes with no InsecureRequestWarning, and requests through the proxy still work.

Verify
gcloud config get core/custom_ca_certs_file

Confirmed by cloud.google.com

Did this fix it?

How do I stop it coming back?

  • Add a CI test step that runs with -W "error:Unverified HTTPS request", so a new verify=False fails the build instead of shipping.
  • Keep internal CA files in one documented path and reference that path in code, rather than disabling checks per call.
  • Ban verify=False and CERT_NONE outside test folders with a grep or lint rule in code review.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.