'urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
import yfinance as yf
msft = yf.Ticker("MSFT")
msft.info
I tried to print msft.info and got 'urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)' error. I tried to rerun the Install Certificates.command and Update Sheet.command but apparently it didn't work. Also after I reran them I got this massage: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/certifi-2021.5.30.dist-info.
Any advices how can I fix it?
Solution 1:[1]
Here are the steps for the MacOs:
- Open the finder
- Find the version of Python that you are using
- Click on the arrow beside Python
- A list will show up under the Python
- Click on the "Install Certificates.command". It will open a terminal and install the certificate.
In my case, I had to do this 2 times before it works. Here is a screenshot from the Finder:
Solution 2:[2]
A quick google search returns the following: http://blog.wafrat.com/fixing-certificate_verify_failed-when-using-yfinances-ticker-info/
As explained in the website linked above, the issue is due to:
It turns out it's because I am running Python on Mac OS and I need to install some certificates (Mac OSX python ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)).
And the solution is to:
So I opened Finder and navigated to Applications, Python 3.7, then ran Install Certificates.command. And it worked indeed!
Solution 3:[3]
I had this problem using Anaconda with Python 3.9, and on Windows - the solution for me was in this answer: How to get and save LetsEncrypt certificates on Windows.
The process is:
- Download "ISRG Root X1", "ISRG Root X2", "Let’s Encrypt R3" (.der files) from https://letsencrypt.org/certificates/
- Follow instructions here: https://www.sonicwall.com/support/knowledge-base/how-can-i-import-certificates-into-the-ms-windows-local-machine-certificate-store/170504615105398/
For this part import the ISRG certs into the 'Certificates/Personal' folder, and import the Let's Encrypt R3 cert into the 'Trusted Root Certification Authorities/Certificates' folder.
- Restart system.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TJ1 |
| Solution 2 | MartinNajemi |
| Solution 3 | zgparsons |

