Pass verify=False to requests.get() / requests.post() (or set session.verify = False on a requests.Session) to disable TLS certificate verification for local development or self-signed endpoints—optionally silencing the resulting InsecureRequestWarning with urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning), while preferring verify="/path/to/ca-bundle.pem" in production so TLS server identity stays protected.
Basic Example
import requests
import urllib3
# 1. Disable SSL verification for a single request:
response = requests.get("https://localhost:8443/health", verify=False, timeout=10)
print(response.status_code)
# Output: 200 (also emits InsecureRequestWarning unless suppressed)
# 2. Suppress the InsecureRequestWarning & configure a reusable Session:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
session = requests.Session()
session.verify = False
res = session.post("https://localhost:8443/api/test", json={"ping": True}, timeout=10)
print(res.json())
# 3. Safer production alternative for internal/self-signed servers:
# Trust your specific root CA .pem file instead of disabling verification completely!
safe_res = requests.get("[https://internal.corp.local/api](https://internal.corp.local/api)", verify="/path/to/internal-ca.pem", timeout=10)
Key Details & Edge Cases
verify=FalsetriggersInsecureRequestWarningon every request unless suppressed:urllib3logsInsecureRequestWarning: Unverified HTTPS request is being made to host '...'to stderr every timeverify=Falseruns.- Silence only that specific warning cleanly with
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)rather than callingwarnings.filterwarnings("ignore")globally (which hides unrelated deprecation or resource warnings).
- Environment variables
REQUESTS_CA_BUNDLEandCURL_CA_BUNDLEoverridesession.verify:- If
REQUESTS_CA_BUNDLEorCURL_CA_BUNDLEis set in your OS environment,requests.Session.merge_environment_settings()can overridesession.verify = Falseunless you explicitly passverify=Falseon the individualsession.get(..., verify=False)call or setsession.trust_env = False.
- If
- Never use
verify=Falseon public networks or production APIs:- Disabling certificate verification still encrypts packets over TLS, but allows any active attacker on the network (public Wi-Fi, compromised router, malicious proxy) to perform a man-in-the-middle (MITM) attack with a forged certificate and read API keys, tokens, or payloads in plaintext.
- For internal enterprise CAs or Zscaler/Netskope proxies, pass
verify="/path/to/corporate-root-ca.pem"(or installpip-system-certs) instead ofverify=False.
- Self-signed client certificates (
cert=) vs. server verification (verify=):- Do not confuse
verify=(validating the server’s SSL certificate) withcert=("/path/to/client.crt", "/path/to/client.key")(mutual TLS client authentication). Even when using mutual TLS (cert=...), keepverify="/path/to/server-ca.pem"enabled.
- Do not confuse
Comparison of SSL Verification Options in Python requests
| Option | Syntax | Validates Server Identity? | Emits InsecureRequestWarning? |
Best Used When |
|---|---|---|---|---|
verify=True (Default) |
requests.get(url) |
Yes (against certifi root CAs) |
No | All production HTTPS requests to public APIs and websites. |
verify="/path/to/ca.pem" |
requests.get(url, verify="ca.pem") |
Yes (against your custom CA file) | No | Corporate TLS proxies, staging servers, or self-signed internal services. |
verify=False |
requests.get(url, verify=False) |
No (vulnerable to MITM attacks) | Yes (unless silenced via urllib3) |
Temporary local testing against https://localhost dev servers with throwaway certs. |
session.verify = False |
s = requests.Session(); s.verify = False |
No | Yes | Applying verify=False across multiple local test requests in one session (pair with s.trust_env = False if env vars interfere). |
You must log in or register to comment.
