python中的许多操作都需要通过https访问.这包括pip安装,或仅使用http.client.HTTPSConnection,或内部使用这些内容的任何模块或应用程序.
如果python是从官方的python pkg安装程序安装的,从https://python.org下载,那么它使用的是openssl的内部版本,并且不包含根证书.任何使用SSL连接的内容都会导致此错误:
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
Run Code Online (Sandbox Code Playgroud)
如何安装根证书以使上述错误消失?
Edw*_*vey 140
运行python安装程序时,它们会向您显示此信息.它也有记录/Applications/Python 3.6/ReadMe.rtf,但很容易被忽视.
只需浏览Applications/Python 3.6并双击即可Install Certificates.command
Python bug跟踪器中存在一个问题. http://bugs.python.org/issue29480
Dav*_*ido 27
无需在 macOS 上检查您的版本,即可为您的所有 Python 版本解决此问题的酷方法
bash /Applications/Python*/Install\ Certificates.command
Run Code Online (Sandbox Code Playgroud)
此命令等效于:
...
bash /Applications/Python\ 2.7/Install\ Certificates.command
bash /Applications/Python\ 3.6/Install\ Certificates.command
bash /Applications/Python\ 3.7/Install\ Certificates.command
...
Run Code Online (Sandbox Code Playgroud)
它帮助了我希望它也能帮助你
小智 17
如果 pip 没有解决问题
pip3 install --upgrade certifi
Run Code Online (Sandbox Code Playgroud)
如果找不到“ Install Certificates.command ”,请尝试以下脚本
#!/usr/bin/env python3
# install_certifi.py
#
# sample script to install or update a set of default Root Certificates
# for the ssl module. Uses the certificates provided by the certifi package:
# https://pypi.python.org/pypi/certifi
import os
import os.path
import ssl
import stat
import subprocess
import sys
STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
| stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
| stat.S_IROTH | stat.S_IXOTH )
def main():
openssl_dir, openssl_cafile = os.path.split(
ssl.get_default_verify_paths().openssl_cafile)
# +++> if already done <----
#print(" -- pip install --upgrade certifi")
#subprocess.check_call([sys.executable,
# "-E", "-s", "-m", "pip", "install", "--upgrade", "certifi"])
import certifi
# change working directory to the default SSL directory
os.chdir(openssl_dir)
relpath_to_certifi_cafile = os.path.relpath(certifi.where())
print(" -- removing any existing file or link")
try:
os.remove(openssl_cafile)
except FileNotFoundError:
pass
print(" -- creating symlink to certifi certificate bundle")
os.symlink(relpath_to_certifi_cafile, openssl_cafile)
print(" -- setting permissions")
os.chmod(openssl_cafile, STAT_0o775)
print(" -- update complete")
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
小智 7
我使用以下命令解决了这个问题:
open /Applications/Python\ 3.7/Install\ Certificates.command
Run Code Online (Sandbox Code Playgroud)
我的机器上装有Python 3.7。
检查此链接- 在Mac上尝试请求HTML时修复CERTIFICATE_VERIFY_FAILED错误
在我的情况下,没有一个解决方案适用于在 macOS Catalina 中安装 python3 的系统,也不适用于通过 brew 安装的 python3。
如果有人遇到这种情况并想要快速解决方案,
请使用https://www.python.org/downloads/再次下载并安装 python3
在安装结束时,安装程序会向您显示一条说明,要求运行该Install Certificates.command文件。
(对于其他安装,此文件不存在,文件源代码的解决方案也不存在)
重新启动终端,您可以键入where python3, 以查看/Library/Frameworks/Python.framework/Versions/3.8/bin/python3。使用这个二进制文件,应该不会出现问题。
注意:有可能使系统安装的 python3 工作,但在我的情况下;事实证明它非常困难,所以我选择了这种方式。
| 归档时间: |
|
| 查看次数: |
42902 次 |
| 最近记录: |