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

Viewed 17312
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?

4 Answers

Here are the steps for the MacOs:

  1. Open the finder
  2. Find the version of Python that you are using
  3. Click on the arrow beside Python
  4. A list will show up under the Python
  5. 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:

enter image description here

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!

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:

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.

This answer got me from 2nd base home, but it skips over that the full path one would want is /Applications/Python 3.x/Install Certificates.command (which was called out in an other question's answer

(I was initially looking in the folder symlinked from /usr/local/bin/python3)

Related