Discord.py ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED]

2022-01-15 00:00:00 python discord.py

问题描述

TLDR:我尝试在我的 Mac 上使用 discord.py 有一段时间了,但我尝试过的所有方法都不起作用.所有其他解决方案都不起作用!

TLDR: I've been trying to use discord.py on my mac for a while, but everything I've tried doesnt work. All the other solutions dont work!

请帮忙.几个月来我一直试图让 Discord.py 工作,但我无法让它工作.这是我的代码 [很明显,我将重置我的令牌]:

Please help. I've been trying to get Discord.py to work for months now, and I can't get it to work. Here's my code [I'll reset my token, obviously]:

import discord


class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        # don't respond to ourselves
        if message.author == self.user:
            return

        if message.content == 'ping':
            await message.channel.send('pong')


client = MyClient()


client.run("NzQxNzUzMTQ0MDA2MTQ4MTU2.Xy8Jcg.wBNInfNrj--ZtinuzQ-b4I7H1jo")

导致以下错误:

Traceback (most recent call last):
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport
    await waiter
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/sslproto.py", line 529, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/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:1123)

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

Traceback (most recent call last):
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/python_bot.py", line 18, in <module>
    client.run("NzQxNzUzMTQ0MDA2MTQ4MTU2.Xy8Jcg.wBNInfNrj--ZtinuzQ-b4I7H1jo")
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/discord/client.py", line 708, in run
    return future.result()
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/discord/client.py", line 687, in runner
    await self.start(*args, **kwargs)
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/discord/client.py", line 650, in start
    await self.login(*args, bot=bot)
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/discord/client.py", line 499, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/discord/http.py", line 291, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/discord/http.py", line 185, in request
    async with self.__session.request(method, url, **kwargs) as r:
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/aiohttp/client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/aiohttp/client.py", line 480, in _request
    conn = await self._connector.connect(
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 858, in _create_connection
    _, proto = await self._create_direct_connection(
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 1004, in _create_direct_connection
    raise last_exc
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 980, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/Users/meow/programming/PycharmProjects/BulmeniBot/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 938, in _wrap_create_connection
    raise ClientConnectorCertificateError(
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:1123)')]

Process finished with exit code 1

我在 mac 上,使用 python 3.8 和 Pycharm.

I'm on mac, using python 3.8 with Pycharm.

经过一番谷歌搜索后,我找到了 this 线程,而这又是引导我这里.双击 Install Certificates.command 给我这个错误:

After some Googling, I got to this thread, which in turn led me here. Double clicking on Install Certificates.command gives me this error:

subprocess.CalledProcessError: Command '['/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8', '-E', '-s', '-m', 'pip', 'install', '--upgrade', 'certifi']' returned non-zero exit status 1.

在谷歌搜索之后,这导致我 this 线程,它没有告诉我任何事情,因为我我只是在使用我的终端.:(

After some more googling, that lead me to this thread, which doesnt tell me anything since I'm just using my terminal. :(

我也尝试过 pip install --upgrade certifi,但错误仍然存​​在.那我该怎么办?

I've tried pip install --upgrade certifi too, but the errors still remains. So what do I do?


解决方案

在 Mac 上,转到 Macintosh HD >应用 >Python3.x 文件夹(x 是你的 python3 版本)>双击安装 Certificates.command";文件

On a mac, go to Macintosh HD > Applications > Python3.x folder (x being your python3 version) > double click on "Install Certificates.command" file

相关文章