Solve – certificate verify failed: unable to get local issuer certificate in Python

Solve – certificate verify failed: unable to get local issuer certificate in Python is an error which occurs in Python when the site you are trying to access has no ssl certificate.

In this blog post I am going to try and solve the error while I try to explain why we get the error.

We will also introduce some solutions that have worked for other developers and that I have personally tested, hopefully we can help you fix your issue.

Explaining the Error : certificate verify failed: unable to get local issuer certificate in Python

The problem happens when the site you are trying to access has no ssl certificate.

The error message should look like the error in the example bellow.

                                                                       #
certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)
                                                                       #

This issue usually happens to people who are using Python, openssl or a scraping tool like Selenium or scrapy, the error occurs when trying to access the server that has no ssl certificate.

Bellow we will describe how the error can be solved. With multiple possible solutions.

Solution 1 : Installing the missing ssl certificate

The first solution is simple, try navigating to the folder of Python 3.x depending on your version of Python. If you do not know where it is located, it is usually in the PATH bellow.

                                                                       #
/Applications/Python 3.7/
                                                                       #

Inside the folder, you should look for a file called Install Certificates.command.

This is a .command file which means you can just just double-click it and it will run in the Terminal.

Doing that will install the certificate and as a result the error should be gone on the next run.

If you are command line person, you can Cd into the directory and install the certficate from the terminal.

Solution 2 : Create a symlink from OS certificates

If you are on MacOS and using pyenv, just run the command bellow.

                                                                       #
ln -s /etc/ssl/* /Library/Frameworks/Python.framework/Versions/3.9/etc/openssl
                                                                       #

The command will Create a symlink from OS certificates to Python. If this helped You, congratulations. If not check out our last solution if you have MacOS.

Solution 3 : Installing the certificate on MacOS

If you have MacOS, you can try installing a certificate package in your device in order for you to be able to use trust certificates in your system.

You can do that by navigating to the path bellow and double clicking the file certificates.command, this will install the certificate on your device.

                                                                       #
open /Applications/Python\ 3.6/Install\ Certificates.command
                                                                       #

I hope this guide solved your problem, thank you for reading.

Summing-up

That’s it fellow developers, this is the end of this guide, I hope you found this useful in solving your particular issue, if you have the means and want to help, please support our work on our Kofi account, you do not have to, but you can donate if you want.

Thank you, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/