Note: This solution is a complete hack. And works only for requests < 2.28 (https://github.com/psf/requests/pull/6074)

Short answer: Set the CURL_CA_BUNDLE environment variable to an empty string.

Before:

$ python
import requests
requests.get('http://www.google.com')
<Response [200]>

requests.get('https://www.google.com')
...
File "/usr/local/lib/python2.7/site-packages/requests-2.17.3-py2.7.egg/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)",)

After:

$ CURL_CA_BUNDLE="" python
import requests
requests.get('http://www.google.com')
<Response [200]>

requests.get('https://www.google.com')
/usr/local/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning)
<Response [200]>

How it works

This solution works because Python requests overwrites the default value for verify from the environment variables CURL_CA_BUNDLE and REQUESTS_CA_BUNDLE, as can be seen here:

if verify is True or verify is None:
verify = (os.environ.get('REQUESTS_CA_BUNDLE') or
    os.environ.get('CURL_CA_BUNDLE'))

The environment variables are meant to specify the path to the certificate file or CA_BUNDLE and are copied into verify. However, by setting CURL_CA_BUNDLE to an empty string, the empty string is copied into verify and in Python, an empty string evaluates to False.

Note that this hack only works with the CURL_CA_BUNDLE environment variable - it does not work with the REQUESTS_CA_BUNDLE. This is because verify is set with the following statement:

verify = (os.environ.get('REQUESTS_CA_BUNDLE') or os.environ.get('CURL_CA_BUNDLE'))

It only works with CURL_CA_BUNDLE because '' or None is not the same as None or '', as can be seen below:

print repr(None or "")
# Prints: ''
print repr("" or None )
# Prints: None
Answer from Moshe on Stack Overflow
Top answer
1 of 3
57

Note: This solution is a complete hack. And works only for requests < 2.28 (https://github.com/psf/requests/pull/6074)

Short answer: Set the CURL_CA_BUNDLE environment variable to an empty string.

Before:

$ python
import requests
requests.get('http://www.google.com')
<Response [200]>

requests.get('https://www.google.com')
...
File "/usr/local/lib/python2.7/site-packages/requests-2.17.3-py2.7.egg/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)",)

After:

$ CURL_CA_BUNDLE="" python
import requests
requests.get('http://www.google.com')
<Response [200]>

requests.get('https://www.google.com')
/usr/local/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning)
<Response [200]>

How it works

This solution works because Python requests overwrites the default value for verify from the environment variables CURL_CA_BUNDLE and REQUESTS_CA_BUNDLE, as can be seen here:

if verify is True or verify is None:
verify = (os.environ.get('REQUESTS_CA_BUNDLE') or
    os.environ.get('CURL_CA_BUNDLE'))

The environment variables are meant to specify the path to the certificate file or CA_BUNDLE and are copied into verify. However, by setting CURL_CA_BUNDLE to an empty string, the empty string is copied into verify and in Python, an empty string evaluates to False.

Note that this hack only works with the CURL_CA_BUNDLE environment variable - it does not work with the REQUESTS_CA_BUNDLE. This is because verify is set with the following statement:

verify = (os.environ.get('REQUESTS_CA_BUNDLE') or os.environ.get('CURL_CA_BUNDLE'))

It only works with CURL_CA_BUNDLE because '' or None is not the same as None or '', as can be seen below:

print repr(None or "")
# Prints: ''
print repr("" or None )
# Prints: None
2 of 3
4

I saw this hack only due to some trouble with my private CA.

The given hack with CURL_CA_BUNDLE='' will not longer work in 2022 with next minor release of requests (that means 2.28 ?).

Please refer to GH issue 6071 which was fixed 6 days before in Feb. 2022

🌐
GitHub
github.com › psf › requests › issues › 6071
CURL_CA_BUNDLE= disables certificate verification · Issue #6071 · psf/requests
February 23, 2022 - I'm not the first to notice this, see: https://stackoverflow.com/questions/48391750/disable-python-requests-ssl-validation-for-an-imported-module Which implies people have even relied on the current behavior as a hack ... but I think it'...
Author   owtaylor
Discussions

How can I disable SSL verification, when using OpenAi API in python?
Due to my network env., I have no choice but to set “SSL verification” disabled. I could set it in python when using “requests” for any other API, -requests.post(…, verify=False) -requests.get(…, verify=False). But how could I make SSL verification disabled when I use ... More on community.openai.com
🌐 community.openai.com
8
1
March 21, 2023
SSL Verify in other modules that use requests (not using requests myself)
https://stackoverflow.com/questions/15445981/how-do-i-disable-the-security-certificate-check-in-python-requests More on reddit.com
🌐 r/learnpython
1
0
May 31, 2023
How to use environment variable to config verify_ssl
I dont want config in front-end project, so used the environment variable to config. My sentry domain is ‘https’ agreement if use ‘.sentryclirc’ set verify_ssl could work. api docs writes: (http.verify_ssl): This can be used to disable SSL verification when set to false. More on forum.sentry.io
🌐 forum.sentry.io
4
0
October 9, 2021
https - How do I disable the security certificate check in Python's Requests? - Stack Overflow
You can override cert_reqs instead ... self: ssl.CERT_NONE, lambda self, newval: None) 2022-05-17T04:34:16.79Z+00:00 ... @Misty Good addition thanks! indeed answer is for previous versions (2021) 2022-05-21T12:25:26.727Z+00:00 ... This was due to a bug in session.verify=False that makes urllib* ignore that when an environment variable (CURL_CA_BUNDLE) ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Conda
docs.conda.io › projects › conda › en › stable › user-guide › configuration › disable-ssl-verification.html
Disabling SSL verification — conda 26.3.2 documentation
To disable SSL verification when using conda skeleton pypi, set the SSL_NO_VERIFY environment variable to either 1 or True (case insensitive).
🌐
Conda
docs.conda.io › projects › conda › en › latest › user-guide › configuration › disable-ssl-verification.html
Disabling SSL verification — conda 24.11.4.dev37 documentation
To disable SSL verification when using conda skeleton pypi, set the SSL_NO_VERIFY environment variable to either 1 or True (case insensitive).
🌐
DEV Community
dev.to › toby-patrick › how-to-fix-ssl-certificateverifyfailed-in-python-requests-35nl
How to Fix “SSL: CERTIFICATE_VERIFY_FAILED” in Python Requests - DEV Community
September 15, 2025 - This environment variable ensures that all requests made using requests use your trusted root certificate. Outdated versions of Python may ship with obsolete CA certificates. You should upgrade Python to the latest official version, especially if you're using anything older than 3.8. Additionally, ensure your system OpenSSL libraries are current. If you’re in a local environment and need a quick workaround for testing, you can disable certificate verification...
🌐
ScrapingAnt
scrapingant.com › blog › requests-ignore-ssl
How to Ignore SSL Certificate in Python Requests Library | ScrapingAnt
August 16, 2024 - This approach can be particularly useful in scenarios where you need to disable SSL verification across different scripts or applications without modifying the code directly. You can set the REQUESTS_CA_BUNDLE environment variable to an empty string or a non-existent file:
🌐
HTTPX
python-httpx.org › advanced › ssl
SSL - HTTPX
>>> httpx.get("https://expired.badssl.com/") httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997) You can disable SSL verification completely and allow insecure requests...
Find elsewhere
🌐
HayaGeek
hayageek.com › home › disable ssl verification in python – requests, urllib3
Disable SSL Verification in Python - requests, urllib3
February 7, 2024 - To suppress these warnings, you can adjust the logging level for urllib3. ... Alternatively, you can set REQUESTS_CA_BUNDLE environment variable to an empty string or to a non-existent file will effectively disable SSL verification.
🌐
ProxiesAPI
proxiesapi.com › articles › expert-techniques-for-disabling-ssl-certificate-verification-in-python-requests
Expert Techniques for Disabling SSL Certificate Verification in Python Requests | ProxiesAPI
Here are answers to some common questions about disabling SSL certificate verification in Python Requests: How can I disable verification for just one request? ... REQUESTS_CA_BUNDLE environment variable to the cert location.
🌐
Reddit
reddit.com › r/learnpython › ssl verify in other modules that use requests (not using requests myself)
r/learnpython on Reddit: SSL Verify in other modules that use requests (not using requests myself)
May 31, 2023 -

Hello,
I'm trying to set up python on a Windows computer to run some scripts to migrate from an old PBX server. We have our own internal PKI and the certs are in the wincertstore. The pbx uses our certs (although for the API, it might use it's own signed cert). Either way, since it's going away, I don't really want to fix certs on it. I'd rather have python ignore these errors just to get through an intern being able to use it to pull some data, migrate users, and be done with this thing.
I'm using the ciscoaxl module which in turn relies on requests. I've read a ton of posts about how to ignore SSL certs when using requests, but how can I do that when it's just another module calling (ciscoaxl) calling requets? I think my best bet is an environment variable but I cannot find one other than to point it at a CA bundle (and not totally clear how to make that in windows).
Either way, is there a way I can pass verify=False in to the ciscoaxl module for requests to then ignore it? Is there an env var I can set to do it globally? Or do I basically need to pull the module's source and update the code for my own use?

🌐
Sentry
forum.sentry.io › on-premise
How to use environment variable to config verify_ssl - On-Premise - #sentry
October 9, 2021 - I dont want config in front-end project, so used the environment variable to config. My sentry domain is ‘https’ agreement if use ‘.sentryclirc’ set verify_ssl could work. api docs writes: (http.verify_ssl): This can be used to disable SSL verification when set to false.
Top answer
1 of 15
923

From the documentation:

requests can also ignore verifying the SSL certificate if you set verify to False.

>>> requests.get('https://kennethreitz.com', verify=False)
<Response [200]>

If you're using a third-party module and want to disable the checks, here's a context manager that monkey patches requests and changes it so that verify=False is the default and suppresses the warning.

import warnings
import contextlib

import requests
from urllib3.exceptions import InsecureRequestWarning

old_merge_environment_settings = requests.Session.merge_environment_settings

@contextlib.contextmanager
def no_ssl_verification():
    opened_adapters = set()

    def merge_environment_settings(self, url, proxies, stream, verify, cert):
        # Verification happens only once per connection so we need to close
        # all the opened adapters once we're done. Otherwise, the effects of
        # verify=False persist beyond the end of this context manager.
        opened_adapters.add(self.get_adapter(url))

        settings = old_merge_environment_settings(self, url, proxies, stream, verify, cert)
        settings['verify'] = False

        return settings

    requests.Session.merge_environment_settings = merge_environment_settings

    try:
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', InsecureRequestWarning)
            yield
    finally:
        requests.Session.merge_environment_settings = old_merge_environment_settings

        for adapter in opened_adapters:
            try:
                adapter.close()
            except:
                pass

Here's how you use it:

with no_ssl_verification():
    requests.get('https://wrong.host.badssl.example/')
    print('It works')

    requests.get('https://wrong.host.badssl.example/', verify=True)
    print('Even if you try to force it to')

requests.get('https://wrong.host.badssl.example/', verify=False)
print('It resets back')

session = requests.Session()
session.verify = True

with no_ssl_verification():
    session.get('https://wrong.host.badssl.example/', verify=True)
    print('Works even here')

try:
    requests.get('https://wrong.host.badssl.example/')
except requests.exceptions.SSLError:
    print('It breaks')

try:
    session.get('https://wrong.host.badssl.example/')
except requests.exceptions.SSLError:
    print('It breaks here again')

Note that this code closes all open adapters that handled a patched request once you leave the context manager. This is because requests maintains a per-session connection pool and certificate validation happens only once per connection so unexpected things like this will happen:

>>> import requests
>>> session = requests.Session()
>>> session.get('https://wrong.host.badssl.example/', verify=False)
/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
<Response [200]>
>>> session.get('https://wrong.host.badssl.example/', verify=True)
/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
<Response [200]>
2 of 15
219

Use requests.packages.urllib3.disable_warnings() and verify=False on requests methods.

Note that you can either import urllib3 directly or import it from requests.packages.urllib3 to be sure to use the same version as the one in requests.

import requests

import urllib3
# or if this does not work with the previous import:
# from requests.packages import urllib3  

# Suppress only the single warning from urllib3.
urllib3.disable_warnings(category=urllib3.exceptions.InsecureRequestWarning)

# Set `verify=False` on `requests.post`.
requests.post(url='https://example.com', data={'bar':'baz'}, verify=False)

And if you want to suppress the warning from urllib3 only when used by the requests methods, you can use it in a context manager:

with urllib3.warnings.catch_warnings():
   urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

   requests.post(url='https://example.com', data={'bar':'baz'}, verify=False)
🌐
D4d
d4d.lt › home › general › how to fix python ssl certificate_verify_failed
How to fix python SSL CERTIFICATE_VERIFY_FAILED – D4D Blog
July 1, 2018 - raise ApiError("HTTP Error: %s" ... claims to be. As a quick (and insecure) fix, you can turn certificate verification off, by: 1. Set PYTHONHTTPSVERIFY environment variable to 0....
🌐
NetApp Community
community.netapp.com › t5 › Software-Development-Kit-SDK-and-API-Discussions › Python-How-to-disable-SSL-certificate-verification › td-p › 113697
Solved: Python - How to disable SSL certificate verification - NetApp Community
October 20, 2021 - import ssl try: _create_unverified_https_context = ssl._create_unverified_context except AttributeError: # Legacy Python that doesn't verify HTTPS certificates by default pass else: # Handle target environment that doesn't support HTTPS verification ssl._create_default_https_context = _create_unverified_https_context
🌐
Conda
docs.conda.io › projects › conda › en › 24.3.x › user-guide › configuration › disable-ssl-verification.html
Disabling SSL verification — conda 24.3.1.dev2 documentation
To disable SSL verification when using conda skeleton pypi, set the SSL_NO_VERIFY environment variable to either 1 or True (case insensitive).
🌐
Delft Stack
delftstack.com › home › howto › python › python requests ignore ssl
How to Ignore SSL Security Certificate Check in Python Requests | Delft Stack
February 2, 2024 - import warnings import contextlib import requests from urllib3.exceptions import InsecureRequestWarning old_merge_environment_settings = requests.Session.merge_environment_settings @contextlib.contextmanager def no_ssl_verification(): opened_adapters = set() def merge_environment_settings(self, url, proxies, stream, verify, cert): opened_adapters.add(self.get_adapter(url)) settings = old_merge_environment_settings( self, url, proxies, stream, verify, cert ) settings["verify"] = False return settings requests.Session.merge_environment_settings = merge_environment_settings try: with warnings.cat
🌐
Readthedocs
libcloud.readthedocs.io › en › stable › other › ssl-certificate-validation.html
SSL Certificate Validation in <v2.0 — Apache Libcloud 3.8.0 documentation
To disable SSL certificate validation, set libcloud.security.VERIFY_SSL_CERT variable to False at the top of your script, before instantiating a driver and interacting with other Libcloud code.
🌐
GitHub
github.com › ccxt › ccxt › issues › 5394
How to disable SSL certificate verification in Python? · Issue #5394 · ccxt/ccxt
June 29, 2019 - (Caused by SSLError(SSLCertVerificationError("hostname 'pro.coinbase.com' doesn't match 'Felipes-MacBook-Pro.local'"))) Which is also warranted, but a check I would much rather disable. Any help would be appreciated. My idea would be something simple as: ex = getattr(ccxt, exchange)( { "session": cfscrape.create_scraper(), "enableRateLimit": False, "verify_ssl_certificates": False, } )
Author   synchronizing