python - discord.py `SSL certificate verify failed` 错误

标签 python ssl discord.py

任何基于 discord.py 结果错误的 python 程序:

Traceback (most recent call last):
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1081, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1111, in _create_connection_transport
    await waiter
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/sslproto.py", line 528, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/sslproto.py", line 188, in feed_ssldata
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 944, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/user/Documents/DroppingBOt.py", line 54, in <module>
    bot.run(DISCORD_BOT_TOKEN)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/discord/client.py", line 723, in run
    return future.result()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/discord/client.py", line 702, in runner
    await self.start(*args, **kwargs)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/discord/client.py", line 665, in start
    await self.login(*args, bot=bot)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/discord/client.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/discord/http.py", line 300, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/discord/http.py", line 192, in request
    async with self.__session.request(method, url, **kwargs) as r:
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/aiohttp/connector.py", line 971, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host discord.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')]
仅当您包含字符串时才会出现
bot.run(DISCORD_BOT_TOKEN)
所以我很确定它甚至可能是 request库问题。
有谁知道其中的原因?
我试图重新安装 discord.py
我尝试在其他 PC 上运行
两台PC都是MacOS

最佳答案

快速说明(您无需阅读此内容):SSL 是一种加密算法,用于在客户端和主机之间安全地传输数据,以防止 MITM(中间人)和其他攻击。您需要一个证书来确保主机是可验证的来源,而不是伪装的黑客。
由于您的两台 Mac 似乎都无法正常工作,这可能是由于您的网络防火墙拒绝访问特定证书,或者它可能根本没有安装。尝试在不同的网络上使用 mac,然后重新安装 discord.py,但建议 这可能行不通 .如果还是不行,引用这里:https://www.digicert.com/kb/ssl-support/p12-import-export-mac-mavericks-server.htm
但是要非常小心。虽然这种情况不太可能发生,但如果 bot 过去可以工作而现在不能工作,则可能意味着您的网络已被黑客入侵,可能使用了 DNS 中毒。如果这些解决方案都不起作用,请尝试使用 replit 之类的在线 IDE。
编辑:也看看这里:Scraping: SSL: CERTIFICATE_VERIFY_FAILED error for http://en.wikipedia.org

关于python - discord.py `SSL certificate verify failed` 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70264948/

相关文章:

heroku - discord.py Heroku FFmpeg 问题

Python Discord 机器人故障排除

python - 有没有办法检查用户和通行证在 python 3 中的 gmail 中是否有效?

python - 通过类创建 pandas DataFrame 返回空 DataFrame

ssl - 我如何在 Mule 中设置密码套件

c# 与 c++ ssl_connect

python - Discord py - 如何提高代码速度?

python - 将列表随机分成两个或三个项目的 block

python - 使用Python拍照

c - 链接到不同版本的 SSL 共享库