25
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?

Alan
  • 253
  • 1
  • 3
  • 5

6 Answers6

99

Here are the steps for macOS:

  1. Open the folder /Applications/Python 3.x (x is the version you are running).
  2. Double click the Install Certificates.command. It will open a terminal and install the certificate.

In my case, I had to do this twice before it worked. Here is a screenshot from the Finder:

Finder screenshot

Janosh
  • 3,392
  • 2
  • 27
  • 35
TJ1
  • 7,578
  • 19
  • 76
  • 119
16

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!

MartinNajemi
  • 514
  • 3
  • 18
  • I tried to rerun the Install Certificates.command and Update Sheet.command but it didn't work. – Alan Jul 09 '21 at 17:41
  • @AlanAkilkhanov Did you rerun it for the same version of python that you are trying to execute with? Did you get an error when re-running the Install Certificates.command? – MartinNajemi Jul 10 '21 at 13:07
  • Sorry for late response. I fixed the problem. – Alan Jul 13 '21 at 16:23
  • @AlanAkilkhanov Please explain how you fixed the problem in case someone else has the same problem :) – MartinNajemi Jul 14 '21 at 15:40
  • Honestly, I didn't really fixed it. I just stated to get a different error for some reason. I don't know how it happened. :( – Alan Jul 14 '21 at 20:20
  • I have the same problem and need help. When I click the Install Certificate file, it shows an error ```ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/certifi' Consider using the `--user` option or check the permissions. ``` I don't know where to add the --user? Because it's just click the file, not typing it. – Megan Jul 31 '22 at 17:42
  • @Megan Apologies for the late reply. Hope you've fixed it, if you haven't and for any future visitors, try using the following command, replace the path to the path where your certificate file is: `sudo open /Applications/Python\ 3.7/Install\ Certificates.command` – MartinNajemi Nov 05 '22 at 22:15
1

If you have error [Errno 13] Permission denied: with InstallCertificates.command, open script in text editor, copy code and run in terminal with sudo su.

user15228599
  • 11
  • 1
  • 3
1

I had the same problem in an virtual environment created with Poetry in Windows. I solved it removing the venv, then reinstalling all the deps.

itacode
  • 3,721
  • 3
  • 21
  • 23
  • I was also facing this in a poetry venv and tried so many other solutions that didn't work. This worked for me. Thank you! – JD White Mar 27 '23 at 01:38
0

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.
zgparsons
  • 1
  • 1
0

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)

Adam Smooch
  • 1,167
  • 1
  • 12
  • 27