错误
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
我尝试过的
我所有的在线搜索都给出以下两个建议之一:
certifi
Install Certificates.command
文件夹中的/Applications/Python 3.X/
最小复制示例
创建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上没有遇到此相同错误。
是否有办法]
--insecure
标志),或错误ssl.SSLCertVerificationError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:无法获取本地发行者证书(_ssl.c:1056)SSL握手在验证...时失败了]]
我也需要解决此问题
hostname = 'www.python.org'
context = ssl.create_default_context()
with socket.create_connection((hostname, 443)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
print(ssock.version())