Mac OSX python ssl.SSLError: [SSL: CERTIFICATE_VER

2020-01-23 05:11发布

Many operations in python require accessing things via https. This includes pip install, or just using http.client.HTTPSConnection, or any modules or applications that use these things internally.

If python was installed from the official python pkg installer, downloaded from https://python.org, then it uses an internal version of openssl, and contains no root certificates. Anything that uses an SSL connection results in this error:

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

How can I install root certs to make the above error go away?

标签: python macos ssl
6条回答
该账号已被封号
2楼-- · 2020-01-23 05:29

I faced the same problem, when I tried to run Python with Keras data loading. The error for me was:

Exception: URL fetch failure on AWS_URL: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)

I fixed my problem by upgrading the certificate as:

pip install --upgrade certifi
查看更多
家丑人穷心不美
3楼-- · 2020-01-23 05:30

In my case none of the solutions worked with the system installed python3 in macOS Catalina, neither did it work with python3 installed via brew.

If someone has a situation like this and wants a quick solution,
Download and install python3 again, using https://www.python.org/downloads/

At the end of the installation, the installer would show you a note, asking to run the Install Certificates.command file.
(With the other installations, this file was not present, and neither was the solution with the file's source code working)

Restart the terminal, and you can type where python3, to see /Library/Frameworks/Python.framework/Versions/3.8/bin/python3. Using this binary, the problem should not occur.

Note: It might be possible to make the system-installed python3 work, but in my case; it proved to be extremely hard, so I choose this way.

查看更多
孤傲高冷的网名
4楼-- · 2020-01-23 05:39

If you're using macOS open finder and go to Applications > Python3.7 folder (or whatever version of python you're using) > double click on "Install Certificates.command" file.

查看更多
Summer. ? 凉城
5楼-- · 2020-01-23 05:42

A cheap way around this is just using python3.5 if you still have it installed.

Pushing to PyPI:

python3.5 setup.py register -r pypitest

python3.5 setup.py sdist upload -r pypitest

pipping seems to work fine with 3.6 out of the box..

查看更多
来,给爷笑一个
6楼-- · 2020-01-23 05:45

I solved this problem using this command:

open /Applications/Python\ 3.7/Install\ Certificates.command

I have Python 3.7 in my machine.

Check this link - Fixing CERTIFICATE_VERIFY_FAILED error when trying requests-html out on Mac

查看更多
我欲成王,谁敢阻挡
7楼-- · 2020-01-23 05:47

When you run the python installer, they display this information to you. It is also documented in /Applications/Python 3.6/ReadMe.rtf, but it's very easily overlooked.

Just browse to Applications/Python 3.6 and double-click Install Certificates.command

There is an issue in the Python bug tracker about this. http://bugs.python.org/issue29480

Update: This issue is marked as resolved in the bug tracker with this comment being the latest one:

For 3.7.0b2, I have tried to make things more obvious in two ways. One, the installer package will now attempt to open a Finder window for the /Application/Python 3.7 folder that contains the "Install Certificates.command". Two, rather than just a generic "installation complete" message at the end of the install, there is now a tailored message that urges the user to click on the "Install Certificates.command" icon.

查看更多
登录 后发表回答