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 to disable SSL certificate verification in Python?
I have read the docs up and down and I can't seem to find a reference for disabling SSL certificate verification. As of right now, I currently have a project where I am doing an intentional man-in-... More on github.com
🌐 github.com
51
June 29, 2019
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
Can I turn off Python (PiP) SSL cert validation with an ENV variable? - Stack Overflow
I have a really bad network that uses a MITM cert to snoop on everyone's convos. This means I need to turn it off, for example, in node I use export NODE_TLS_REJECT_UNAUTHORIZED="0". Is there a si... More on stackoverflow.com
🌐 stackoverflow.com
Option to disable SSL verification
I have searched the issues of this repo and believe that this is not a duplicate. I have searched the documentation and believe that my question is not covered. Feature Request This is mainly a rev... More on github.com
🌐 github.com
4
September 1, 2022
🌐
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).
🌐
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
🌐
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.
🌐
Dnaeon
dnaeon.github.io › disable-python-ssl-verification
Disable SSL verification in Python
December 28, 2014 - In order to disable HTTPS certificate validation by default in Python versions 2.7.9 or above you could use this snippet of code. 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
🌐
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.
Find elsewhere
🌐
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).
🌐
CopyProgramming
copyprogramming.com › howto › python-disable-ssl-verification-environment-variable
Python: Environment variable to turn off SSL verification in Python
March 30, 2023 - The website https://github.com... ... The writers added an environment variable for disable SSL verification which has the added advantage of suppressing the insecure request warnings that may be printed by urllib3. To execute python script , simply set the variable in your shell beforehand...
🌐
GitHub
github.com › python-poetry › poetry › issues › 6331
Option to disable SSL verification · Issue #6331 · python-poetry/poetry
September 1, 2022 - to do so, the popular workaround was setting CURL_CA_BUNDLE="" so that requests does not verify SSL · poetry 1.2.0 is based on a recent version of requests, which removed this workaround recently and refuse to have a way to set this using ...
Author   simonvdk
🌐
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.
🌐
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...
🌐
Python
bugs.python.org › issue23857
Issue 23857: Make default HTTPS certificate verification setting configurable - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/68045
🌐
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:
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)
🌐
Better Stack
betterstack.com › community › questions › pip-install-fails-with-ssl-certificate-verify-failed
Pip Install Fails With "Connection Error: [Ssl: Certificate_verify_failed] Certificate Verify Failed (_ssl.c:598)" | Better Stack Community
Download the latest cacert.pem file from the certifi GitHub repository. Replace the existing cacert.pem file in your Python installation's certifi directory with the newly downloaded file. The directory can typically be found here: Windows: C:\\PythonXX\\Lib\\site-packages\\certifi · macOS/Linux: /usr/local/lib/pythonX.X/site-packages/certifi · As a last resort, you can disable SSL verification entirely.
🌐
Shuaib Mohammad
shuaib.org › technical-guide › resolving-python-requests-tls-ssl-certificate-verification-errors
Resolving Python Requests TLS/SSL Certificate Verification Errors
January 22, 2023 - requests.get('https://github.com', ... making your eyes sore. Can't this be set globally? Well, yes it can! Enter the REQUESTS_CA_BUNDLE environment variable......
🌐
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?