回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>TLDR:我已经尝试在我的mac上使用discord.py有一段时间了,但是我尝试的一切都不起作用。所有其他解决方案都不起作用</p>
<p>请帮忙。几个月来,我一直试图让Discord.py工作,但我无法让它工作。这是我的代码[显然,我会重置我的令牌]:</p>
<pre><code>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")
</code></pre>
<p>这将导致以下错误:</p>
<pre><code>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
</code></pre>
<p>我在mac上,使用Python3.8和Pycharm</p>
<h2>我所尝试的:</h2>
<p>通过谷歌搜索,我找到了<a href="https://github.com/Rapptz/discord.py/issues/4159" rel="nofollow noreferrer">this</a>线程,这反过来又导致了我<a href="https://github.com/Rapptz/discord.py/issues/423#issuecomment-272093801" rel="nofollow noreferrer">here</a>。双击<code>Install Certificates.command</code>会出现以下错误:</p>
<pre><code>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.
</code></pre>
<p>在更多的谷歌搜索之后,我找到了<a href="https://bugs.python.org/issue36340" rel="nofollow noreferrer">this</a>线程,它没有告诉我任何事情,因为我只是在使用我的终端(</p>
<p>我也试过<code>pip install --upgrade certifi</code>,但错误仍然存在。那我该怎么办</p>