【发布时间】:2020-03-06 18:09:33
【问题描述】:
错误
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056) SSL 握手验证证书失败
aiohttp.client_exceptions.ClientConnectorCertificateError: 无法连接到主机 discordapp.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056) ')]
完整回溯(156 行):https://pastebin.com/xmy4aYcM
调试信息
我在 Raspberry Pi 3 上使用 Python 3.7.3 在完全更新的 Raspbian Buster 上运行。
uname -a的输出:
Linux hostname 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l GNU/Linux
lsb_release -a 的输出:
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster
pip freeze的输出:
aiohttp==3.5.4
async-timeout==3.0.1
attrs==19.3.0
certifi==2019.9.11
chardet==3.0.4
discord.py==1.2.4
idna==2.8
multidict==4.5.2
pkg-resources==0.0.0
websockets==6.0
yarl==1.3.0
>>> import os
>>> import ssl
>>> openssl_dir, openssl_cafile = os.path.split(
... ssl.get_default_verify_paths().openssl_cafile)
>>> os.listdir(openssl_dir)
['openssl.cnf', 'private', 'misc', 'certs']
>>> print(os.path.exists(openssl_cafile))
False
我的尝试
我所有的在线搜索都给出了以下两个建议之一:
- 使用 pip 安装
certifi- 我已经安装了它,它并没有改变任何东西。
- 在
/Applications/Python 3.X/文件夹中运行Install Certificates.command- 这是特定于 Mac 的。一般来说,所有提到此错误的地方都只在 Mac 上。
最小复制示例
创建一个venv,并安装包
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ca-certificates python3-venv python3-pip
python3 -m venv env
source env/bin/activate
python3 -m pip install -U pip
python3 -m pip install -U setuptools wheel
python3 -m pip install -U discord.py certifi
打开 python3 提示符,然后运行:
import discord
client = discord.Client()
client.run("token") # error happens here
我在运行 Linux 和相同 Python 版本和软件包的 PC 上没有遇到同样的错误。
有办法吗
- 忽略 ssl 证书验证检查(如 curl 上的
--insecure标志),或者 - 正确安装缺少的证书?
【问题讨论】:
标签: python python-3.x ssl certificate raspbian