Try this in the command line:

pip install pip-system-certs

I've been struggling with the CERTIFICATE_VERIFY_FAILED error as well when using the requests module. I tried installing certifi but that didn't help. The only solution to my problem was to install pip-system-certs. For some reason that allowed requests to access a local certificate.

Also: requests.get(url, verify=False) is not recommended for production environment because you basically turn safety off.

Answer from Milo Buwalda on Stack Overflow
🌐
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
The error "ConnectionError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)" occurs when pip is unable to verify the SSL certificate of the repository from which it is trying to download a package.
🌐
Github
chanind.github.io › python › 2023 › 08 › 30 › python-ssl-certificate-verify-failed.html
Solving Python SSL certificate verify failed on Linux / SGE | chanind.github.io
August 30, 2023 - I didn’t have any luck following most of what I found on Stack Overflow to solve this issue, but eventually stumbled on a solution combining ideas from Redhat’s guide to Python cert errors, and a Stack Overlow answer. Specifically, I needed to install certifi certs via pip install certifi, but this was not enough. I then needed to set an ENV var called SSL_CERT_FILE to the location of the certs installed via certifi.
Discussions

python - SSL: CERTIFICATE_VERIFY_FAILED certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)'))) - Stack Overflow
I'm working on scripts to connect to AWS from Win10. When I try to install a python module or execute a script I get the following error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: More on stackoverflow.com
🌐 stackoverflow.com
Getting this error on Linux with requests - SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
FIXED - SSL connection broken, certificate verification error, unable to get local issuer certificat ... Unable to understand "while" loop. ... AAP Containerized Installation Failed at "Could not connect to Redis at XXX.XXX.1.202:6379: SSL_connect failed: certificate verify failed" More on reddit.com
🌐 r/learnpython
8
0
July 15, 2020
Ssl: certificate_verify_failed
I ran this command: sudo /usr/local/bin/certbot-auto certonly --nginx It produced this output: Installing Python packages… Traceback (most recent call last): File “/tmp/tmp.UbY9vbuI2u/pipstrap.py”, line 177, in sy… More on community.letsencrypt.org
🌐 community.letsencrypt.org
1
1
December 12, 2019
certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)
Self Checks I have searched for existing issues search for existing issues, including closed ones. I confirm that I am using English to submit this report (我已阅读并同意 Language Policy). Pleas do not mo... More on github.com
🌐 github.com
8
March 1, 2024
🌐
GitHub
github.com › Rapptz › discord.py › issues › 6934
SSL: CERTIFICATE_VERIFY_FAILED, Ubuntu, tried eveything · Issue #6934 · Rapptz/discord.py
May 20, 2021 - Summary Even with up to date certs, SSL certificate verify still fails. Reproduction Steps Make any discord bot and run it, discord.py will use aiohttp and try to connect to discord.com:443, and get the error Minimal Reproducible Code (a...
Published   May 20, 2021
Author   newperson1746
🌐
Red Hat
access.redhat.com › discussions › 4487561
Unable to verify server's identity: [SSL
I am trying to register but it shows only "Unable to verify server's identity: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed " Could you please help me out and How to register in Subscription Management System : centos 8
Top answer
1 of 1
4

It looks like the context needs to be passed into an HTTPSHandler in order to make use of the certifi certificates.

Try patching your local copy of /usr/local/lib/python3.8/dist-packages/hcaptcha_field/fields.py with the following.

To the imports, as you've already done, add:

import certifi
import ssl

In addition, expand the import from urllib.request to include HTTPSHandler:

from urllib.request import build_opener, Request, ProxyHandler, HTTPSHandler

Also as you've already done, create an SSL context that uses the certifi certificates. I would add this right under the import block, though, rather than deep in the module code:

context=ssl.create_default_context(cafile=certifi.where())

Then, immediately below this new context=... line, create a new HTTPSHandler instance using context:

https_handler = HTTPSHandler(context=context)

Then, revise the line where opener is defined using the build_opener(...) call to include the new HTTPSHandler instance:

opener = build_opener(https_handler, ProxyHandler(hcaptcha_settings.PROXIES))

If I'm reading the build_opener docs correctly, the build_opener machinery is already using a default instance of HTTPSHandler as it tries to open the URL. Hopefully, replacing that default instance with this new https_handler instance, which will operate with the SSL context that includes the certifi certificates, will allow the urlopen call to work.

If this does work, then an issue/PR to the upstream project might be a good idea, to integrate this logic and either to provide a default behavior that pulls in the certifi certificates automatically if they're available, or to include a configuration option to let the user wire in the certifi certificates.


UPDATE 2022-04-14: Since this did fix the problem, I'll add some more detail as to why this fix was necessary and how it worked.

HTTPS requires the website you're accessing to provide a certificate that validates its identity. Otherwise, how do you know your traffic hasn't been messed with, man-in-the-middle attacked, etc.? The certificate that a website provides to you when you browse to it is issued to the operators of the website by a certificate issuing authority. This authority serves as a trusted third party, to "vouch for" the website operators and that, "yes, you can trust this certificate from them".

There are several of these issuing authorities out there. Those authorities issue their own certificates ("certificate authority certificates", or "CA certificates"), which are completely separate from the ones that individual websites provide. Your browser (or URL opener) needs to have access to these CA certificates in order to complete the 'trusted third party' verification of the certificate that the website presents. The key error the OP is facing here is the inability of the URL opener to find a good set of CA certificates to use for this third-party validation:

<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)>

The message unable to get local issuer certificate means that urlopen cannot find the needed issuer certificate (CA certificate) on the local system.

So, the solution is to point urlopen to the CA certificates provisioned by the certifi package:

  • In order to tell the opener where to find them, you have to provide their location when you create opener from build_opener

  • build_opener works based upon a collection of handler objects, so the CA certificate information must be included within a suitable handler

  • The only handler (that I could find in the docs) that includes information about the SSL context is the HTTPSHandler

  • The way that HTTPSHandler takes in information about SSL-related configuration is through the context keyword argument when creating a new instance, which takes an 'SSL context' object

  • ssl.create_default_context is (as best I understand) a factory function for creating SSL context objects, customizeable in various ways

  • One of the ways it's customizeable is with the location of a CA certificate store (via the cafile argument)

  • certifi provides the location on disk of its curated CA certificate store through the certifi.where() function

If you scan these bullets from bottom to top, they map pretty well to each of the steps in the answer.

🌐
Reddit
reddit.com › r/learnpython › getting this error on linux with requests - ssl: certificate_verify_failed] certificate verify failed: unable to get local issuer certificate
r/learnpython on Reddit: Getting this error on Linux with requests - SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
July 15, 2020 - It might. You can try sending a request without certifi · import ssl import requests certs = [p for p in ssl.get_default_verify_paths() if p.endswith('.pem')] for path in certs: requests.get('mysite.com', verify=path)
Find elsewhere
🌐
Red Hat
access.redhat.com › solutions › 6632061
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify ...
October 23, 2025 - Unable to verify server's identity: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:897)
🌐
NXP
community.nxp.com › t5 › Embedded-Software-and-Tools › S32G2-Linux-BSP-33-0-SSL-CERTIFICATE-VERIFY-FAILED-while-doing › td-p › 1619341
S32G2 Linux BSP 33.0: SSL: CERTIFICATE_VERIFY_FAILED while doing repo init for bsp 33.0 - NXP Community
March 21, 2023 - Downloading Repo source from https://gerrit.googlesource.com/git-repo fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852) fatal: double check your --repo-rev setting.
🌐
Better Stack
betterstack.com › community › questions › urllib-and-ssl-certificate-verify-failed-error
Urllib and "Ssl: Certificate_verify_failed" Error | Better Stack Community
The ssl: certificate_verify_failed error when using Python's urllib library indicates that the SSL certificate of the server you're trying to connect to cannot be verified. This typically happens when the server's certificate chain cannot be ...
🌐
GitHub
github.com › langgenius › dify › issues › 2637
certificate verify failed: unable to get local issuer certificate (_ssl.c:1007) · Issue #2637 · langgenius/dify
March 1, 2024 - hi team, we write self define tool, but when test return error:[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)
Author   heywiorld
Top answer
1 of 16
618

This isn't a solution to your specific problem, but I'm putting it here because this thread is the top Google result for "SSL: CERTIFICATE_VERIFY_FAILED", and it lead me on a wild goose chase.

If you have installed Python 3.6 on OSX and are getting the "SSL: CERTIFICATE_VERIFY_FAILED" error when trying to connect to an https:// site, it's probably because Python 3.6 on OSX has no certificates at all, and can't validate any SSL connections. This is a change for 3.6 on OSX, and requires a post-install step, which installs the certifi package of certificates. This is documented in the file ReadMe.rtf, which you can find at /Applications/Python\ 3.6/ReadMe.rtf (see also the file Conclusion.rtf, and the script build-installer.py that generates the macOS installer).

The ReadMe will have you run the post-install script at

/Applications/Python\ 3.10/Install\ Certificates.command (Terminal App, this command alone should, fix the issue. Be sure to update the file path using your current subversion.)

(its source is install_certificates.command), which:

  • first installs the Python package certifi, and
  • then creates a symbolic link from the OpenSSL certificates file to the certificates file installed by the package certifi.

Release notes have some more info: https://www.python.org/downloads/release/python-360/

On newer versions of Python, there is more documentation about this:

  • https://github.com/python/cpython/blob/e05a703848473b0365886dcc593cbddc46609f29/Mac/BuildScript/resources/ReadMe.rtf#L22-L34
  • https://github.com/python/cpython/blob/e05a703848473b0365886dcc593cbddc46609f29/Mac/BuildScript/resources/Conclusion.rtf#L15-L19
  • https://github.com/python/cpython/blob/e05a703848473b0365886dcc593cbddc46609f29/Mac/BuildScript/resources/Welcome.rtf#L23-L25
  • https://github.com/python/cpython/blob/e05a703848473b0365886dcc593cbddc46609f29/Mac/BuildScript/resources/install_certificates.command
  • https://github.com/python/cpython/blob/e05a703848473b0365886dcc593cbddc46609f29/Mac/BuildScript/README.rst
  • https://github.com/python/cpython/blob/e05a703848473b0365886dcc593cbddc46609f29/Mac/BuildScript/build-installer.py#L239-L246
2 of 16
409

If you just want to bypass verification, you can create a new SSLContext. By default newly created contexts use CERT_NONE.

Be careful with this as stated in section 17.3.7.2.1

When calling the SSLContext constructor directly, CERT_NONE is the default. Since it does not authenticate the other peer, it can be insecure, especially in client mode where most of time you would like to ensure the authenticity of the server you’re talking to. Therefore, when in client mode, it is highly recommended to use CERT_REQUIRED.

But if you just want it to work now for some other reason you can do the following, you'll have to import ssl as well:

input = input.replace("!web ", "")      
url = "https://domainsearch.p.mashape.com/index.php?name=" + input
req = urllib2.Request(url, headers={ 'X-Mashape-Key': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' })
gcontext = ssl.SSLContext()  # Only for gangstars
info = urllib2.urlopen(req, context=gcontext).read()
Message.Chat.SendMessage ("" + info)

This should get round your problem but you're not really solving any of the issues, but you won't see the [SSL: CERTIFICATE_VERIFY_FAILED] because you now aren't verifying the cert!

To add to the above, if you want to know more about why you are seeing these issues you will want to have a look at PEP 476.

This PEP proposes to enable verification of X509 certificate signatures, as well as hostname verification for Python's HTTP clients by default, subject to opt-out on a per-call basis. This change would be applied to Python 2.7, Python 3.4, and Python 3.5.

There is an advised opt out which isn't dissimilar to my advice above:

import ssl

# This restores the same behavior as before.
context = ssl._create_unverified_context()
urllib.urlopen("https://no-valid-cert", context=context)

It also features a highly discouraged option via monkeypatching which you don't often see in python:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

Which overrides the default function for context creation with the function to create an unverified context.

Please note with this as stated in the PEP:

This guidance is aimed primarily at system administrators that wish to adopt newer versions of Python that implement this PEP in legacy environments that do not yet support certificate verification on HTTPS connections. For example, an administrator may opt out by adding the monkeypatch above to sitecustomize.py in their Standard Operating Environment for Python. Applications and libraries SHOULD NOT be making this change process wide (except perhaps in response to a system administrator controlled configuration setting).

If you want to read a paper on why not validating certs is bad in software you can find it here!

🌐
SSLInsights
sslinsights.com › home › wiki › how to fix ssl certificate_verify_failed error in python
Fix Python SSL CERTIFICATE_VERIFY_FAILED Error in 2026
3 weeks ago - Your script fails because Python's SSL module blocks connections to websites with certificates it considers untrusted, expired, or improperly configured. This happens most frequently when using libraries like urllib, requests, or pip to fetch ...
🌐
How to Use Linux
howtouselinux.com › home › 5 ways to fix ssl: certificate_verify_failed in python
5 Ways to fix SSL: CERTIFICATE_VERIFY_FAILED in Python - howtouselinux
October 22, 2025 - SSL certificate_verify_failed errors typically occur as a result of outdated Python default certificates or invalid root certificates. We will cover how to fix this issue in 5 ways in this article.
Top answer
1 of 16
608

TLDR:

hostname=XXX
port=443
trust_cert_file_location=`curl-config --ca`

sudo bash -c "echo -n | openssl s_client -showcerts -connect $hostname:$port -servername $hostname \
    2>/dev/null  | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'  \
    >> $trust_cert_file_location"

Warning: as noted in gareththered's excellent answer, this adds all certificates, instead of only the Root CAs.
Blindly adding all (any) certificates to your truststore without due diligence is not the best course of action.


Note: x-yuri adds in the comments:

  • Although echo -n (basically EOF) is a valid way to make s_client exit, you can also do echo Q.
  • sed doesn't need -e if there's only one script.

Long answer

The basic reason is that your computer doesn't trust the certificate authority that signed the certificate used on the GitLab server. This doesn't mean the certificate is suspicious, but it could be self-signed or signed by an institution/company that isn't in the list of your OS's list of CAs. What you have to do to circumvent the problem on your computer is telling it to trust that certificate — if you don't have any reason to be suspicious about it.

You need to check the web certificate used for your GitLab server, and add it to your </git_installation_folder>/bin/curl-ca-bundle.crt.

To check if at least the clone works without checking said certificate, you can set:

export GIT_SSL_NO_VERIFY=1
#or
git config --global http.sslverify false

But that would be for testing only, as illustrated in "SSL works with browser, wget, and curl, but fails with git", or in this blog post.

Check your GitLab settings.


To get that certificate (that you would need to add to your curl-ca-bundle.crt file), type a:

echo -n | openssl s_client -showcerts -connect yourserver.com:YourHttpsGitlabPort \
  2>/dev/null  | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'

(with 'yourserver.com' being your GitLab server name, and YourHttpsGitlabPort is the https port, usually 443)

To check the CA (Certificate Authority issuer), type a:

echo -n | openssl s_client -showcerts -connect yourserver.com:YourHttpsGilabPort \
  2>/dev/null  | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' \
  | openssl x509 -noout -text | grep "CA Issuers" | head -1

Note: Valeriy Katkov suggests in the comments to add -servername option to the openssl command; otherwise the command isn't showed certificate for www.github.com in Valeriy's case.

openssl s_client -showcerts -servername www.github.com -connect www.github.com:443

Findekano adds in the comments:

to identify the location of curl-ca-bundle.crt, you could use the command

curl-config --ca

Also, see my more recent answer "GitHub: server certificate verification failed": you might have to renistall those certificates:

sudo apt-get install --reinstall ca-certificates
sudo mkdir /usr/local/share/ca-certificates/cacert.org
sudo wget -P /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt
sudo update-ca-certificates
git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
2 of 16
415

[!] WARNING: This has major security implications.

Open your terminal and run following command:

export GIT_SSL_NO_VERIFY=1

It works for me and I am using Linux system.

🌐
Sectigo
sectigostore.com › ssl resources › ssl errors › what is an ssl ‘certificate_verify_failed’ error and how do i resolve it?
What is an SSL ‘Certificate_Verify_Failed’ Error and How Do I Resolve It? - SectigoStore
July 1, 2024 - SSL certificate_verify_failed errors typically occur as a result of outdated Python default certificates or invalid root certificates. If you’re a website owner and you’re receiving this error, it could be because you’re not using a valid ...
🌐
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
i'm getting ssl certification verification error / Newbie Corner / Arch Linux Forums
April 14, 2024 - sudo reflector --latest 20 --sort rate --save /etc/pacman.d/mirrorlist --verbose error: failed to retrieve mirrorstatus data: URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)>
🌐
Website Pulse
websitepulse.com › blog › ssl-certificate-verification-failed-fix
SSL Certificate Verification Failed – Fixes & Prevention Guide
August 15, 2025 - In some environments, such as corporate networks, internal APIs, or when using self-signed certificates, the default certificate store may not contain the root Certificate Authority (CA) required to verify the server's SSL/TLS certificate.