文章

Python程序报错-SSL:CERTIFICATE_VERIFY_FAILED

问题

最近更新WebRTC程序执行 gclient sync 命令报错:

主要是证书校验失败

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Syncing projects: 100% (47/47), done.
Running hooks:  32% (10/31) mac_toolchain
________ running 'python3 src/build/mac_toolchain.py' in '/Users/admin/repos/github/webrtc-mirror'
Skipping Mac toolchain installation for mac
Running hooks:  41% (13/31) clang
________ running 'python3 src/tools/clang/scripts/update.py' in '/Users/admin/repos/github/webrtc-mirror'
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)>
Retrying in 5 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)>
Retrying in 10 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)>
Retrying in 20 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)>
Failed to download prebuilt clang package clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
Use build.py if you want to build locally.
Exiting.
Error: Command 'python3 src/tools/clang/scripts/update.py' returned non-zero exit status 1 in /Users/admin/repos/github/webrtc-mirror
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)>
Retrying in 5 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)>
Retrying in 10 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)>
Retrying in 20 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)>
Failed to download prebuilt clang package clang-llvmorg-19-init-2941-ga0b3dbaf-16.tar.xz
Use build.py if you want to build locally.
Exiting.

python 版本是3.11.4, 是从官网下载安装的。

参考了网上的解决办法,无果!更新 depot_tools 也无效,奇怪,奇怪,真奇怪!

分析

可能中间安装过深度学习的依赖,还有pyenv管理过pyhon, 把python 环境搞乱了.

解决

删除pyenv乱七八糟的东西,网上可以搜到,主要是删除 ~/.pyenv目录,以及移除~/.zshrc里的环境变量就可以

删除 ` /Library/Frameworks/Python.framework` , 从官网从新下载 python 安装包,重新安装即可。

默认安装完之后还是会在 ` /Library/Frameworks/Python.framework` 防止python可执行程序

另外再应用程序(Mac的 Application)目录会有一个 Python 3.12 文件夹,里面有个 Install Certificates.command的脚本,终端执行下可能也能解决问题,但是我没试

本文由作者按照 CC BY 4.0 进行授权