I am creating my first python discord bot with the latest version of python installed on Atom. I am currently following a tutorial on YouTube done in Python 3.6.5
https://www.youtube.com/watch?v=nW8c7vT6Hl4
The tutorial has been straightforward, as I pip installed discord and replicated the setup code shown in the tutorial. My code is here (the token will not be shown).
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '!')
#client.event
async def on_ready():
print('Bot is ready.')
client.run('insert token here')
When I run this program, I get this very long error message, which says that the bot cannot connect to the host discord.com:443
Traceback (most recent call last):
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\aiohttp\connector.py", line 936, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 1050, in create_connection
transport, protocol = await self._create_connection_transport(
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 1080, in _create_connection_transport
await waiter
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\asyncio\sslproto.py", line 529, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\asyncio\sslproto.py", line 189, in feed_ssldata
self._sslobj.do_handshake()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\ssl.py", line 944, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1124)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\ayush\OneDrive\Desktop\Coding\discordbot.py", line 10, in <module>
client.run('NzYzOTY2OTg3MzEwOTg5MzEz.X3_Zsw.lbaYvBEk1kR6A58lkF3mqz7jDVc')
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 708, in run
return future.result()
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 687, in runner
await self.start(*args, **kwargs)
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 650, in start
await self.login(*args, bot=bot)
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 499, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\http.py", line 291, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\http.py", line 185, in request
async with self.__session.request(method, url, **kwargs) as r:
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\aiohttp\client.py", line 1012, in __aenter__
self._resp = await self._coro
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\aiohttp\client.py", line 480, in _request
conn = await self._connector.connect(
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\aiohttp\connector.py", line 523, in connect
proto = await self._create_connection(req, traces, timeout)
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\aiohttp\connector.py", line 858, in _create_connection
_, proto = await self._create_direct_connection(
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\aiohttp\connector.py", line 1004, in _create_direct_connection
raise last_exc
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\aiohttp\connector.py", line 980, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "C:\Users\ayush\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\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: certificate has expired (_ssl.c:1124)')]
[Finished in 1.317s]
I have looked at all the similar questions on Stack that may solve this problem, however, the most relevant search simply just said the issue is a server-side problem.
There are two things that might come into consideration.
When I pip installed discord, it worked, however, the command prompt said afterward that I do not have the latest version of pip installed
Could it perhaps be a problem with the version of python. I am using the latest version, and the video tutorial I am following is python 3.6.5
I would appreciate any insight on this issue, as I am relatively new to Python. Thanks!
Related
I had the following error running my discord bot specifically occurring on the line client.run('TOKEN') on Raspbian.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1089, in create_connection
transport, protocol = await self._create_connection_transport(
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1119, in _create_connection_transport
await waiter
File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 534, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 188, in feed_ssldata
self._sslobj.do_handshake()
File "/usr/local/lib/python3.10/ssl.py", line 974, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/pi/Desktop/Bot/bot.py", line 162, in <module>
client.run('OTI4MTQ2MzUwNDMwODg4MDM1.YdUhpg.J-Hw2jZqp_53xOQeqjD67up45T0')
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 723, in run
return future.result()
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 702, in runner
await self.start(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 665, in start
await self.login(*args, bot=bot)
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "/usr/local/lib/python3.10/site-packages/discord/http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "/usr/local/lib/python3.10/site-packages/discord/http.py", line 192, in request
async with self.__session.request(method, url, **kwargs) as r:
File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1117, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 520, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/usr/local/lib/python3.10/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:997)')]
pi#raspberrypi:~/Desktop/Bot $ python3.10 bot.py
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1089, in create_connection
transport, protocol = await self._create_connection_transport(
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1119, in _create_connection_transport
await waiter
File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 534, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 188, in feed_ssldata
self._sslobj.do_handshake()
File "/usr/local/lib/python3.10/ssl.py", line 974, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/pi/Desktop/Bot/bot.py", line 162, in <module>
client.run('OTI4MTQ2MzUwNDMwODg4MDM1.YdUhpg.J-Hw2jZqp_53xOQeqjD67up45T0')
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 723, in run
return future.result()
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 702, in runner
await self.start(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 665, in start
await self.login(*args, bot=bot)
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "/usr/local/lib/python3.10/site-packages/discord/http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "/usr/local/lib/python3.10/site-packages/discord/http.py", line 192, in request
async with self.__session.request(method, url, **kwargs) as r:
File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1117, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 520, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/usr/local/lib/python3.10/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:997)')]
When I input the solution yesterday I found on GitHub it seemed to resolve this issue and the bot was running perfectly fine. I'll include the solution below:
sudo apt install ca-certificates
sudo update-ca-certificates --fresh
export SSL_CERT_DIR=/etc/ssl/certs
I was absolutely mystified when I launched my Raspberry Pi this morning and the issue reoccurred. I tried the solution above again and it did not resolve the issue. Does anyone know why this occurred and what the solution is?
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.13 (stretch)
Release: 9.13
Codename: stretch
Could you try these, I remember having similar issues once on a VirtualBox installation for some distro and I found this somewhere which fixed my issue (can't recall where exactly)
pip install certifi
then after that
sudo update-ca-certificates
certifi is a package that comes preinstalled with requests is what I know and sometimes you might not have it.
PyPi:
https://pypi.org/project/certifi/
Github:
https://github.com/certifi/python-certifi
I am trying to create an admin bot using the discord API. This is the set I have as of yet,
ACCESS_TOKEN = ""
client = discord.Client()
#this identifies when the bot is online and ready to listen for messages
#client.event
async def on_read():
print('Bot is now online and active')
#client.event
async def on_message(message):
if message.author == client.user:
return
await message.channel.send('Hello')
client.run(ACCESS_TOKEN)
When I run it I get a string of errors which I am not sure as to what they mean.
ile "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/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.10/lib/python3.10/asyncio/base_events.py", line 1080, in create_connection
transport, protocol = await self._create_connection_transport(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 1110, in _create_connection_transport
await waiter
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py", line 528, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py", line 188, in feed_ssldata
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 974, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/vipashashah/TCMprojects/midterm APIs2.0/DiscordAPI", line 20, in <module>
client.run(' ')
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/client.py", line 723, in run
return future.result()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/client.py", line 702, in runner
await self.start(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/client.py", line 665, in start
await self.login(*args, bot=bot)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/http.py", line 192, in request
async with self.__session.request(method, url, **kwargs) as r:
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/client.py", line 1117, in __aenter__
self._resp = await self._coro
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/client.py", line 520, in _request
conn = await self._connector.connect(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py", line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
raise last_exc
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/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:997)')]
I removed my access token for security but everything else is the same. I installed the discord package so not sure what went wrong.
This seems to be a problem related to python 3.10 on MacOS.
Easy solution: go back to python 3.9
Look here for more details:
https://githubhot.com/repo/piekstra/tplink-cloud-api/issues/63
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!
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")
Which results in the folowing error:
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
I'm on mac, using python 3.8 with Pycharm.
What I have tried:
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.
After some more googling, that lead me to this thread, which doesnt tell me anything since I'm just using my terminal. :(
I've tried pip install --upgrade certifi too, but the errors still remains. So what do I do?
On a mac, go to Macintosh HD > Applications > Python3.x folder (x being your python3 version) > double click on "Install Certificates.command" file
Try both of these (Windows):
Method #1:
Download and install this certificate here: https://crt.sh/?id=2835394
It can be installed by double clicking the file and installing it to Local Computer.
If you are curious what caused this: https://support.sectigo.com/Com_KnowledgeDetailPage?Id=kA03l00000117LT
Info taken from a discord server
Method #2:
Navigate to your Applications/Python 3.X/ folder and double click the Install Certificates.command to fix this.
This question already has an answer here:
Certifacte verify failed: certificate has expired (_ssl.c:1108)
(1 answer)
Closed 2 years ago.
Hello People
today I started programming my first Discord bot, opting for Python instead of C# for simplicity, and I get following error:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python38-32\lib\site-packages\aiohttp\connector.py", line 936, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "C:\Program Files (x86)\Python38-32\lib\asyncio\base_events.py", line 1050, in create_connection
transport, protocol = await self._create_connection_transport(
File "C:\Program Files (x86)\Python38-32\lib\asyncio\base_events.py", line 1080, in _create_connection_transport
await waiter
File "C:\Program Files (x86)\Python38-32\lib\asyncio\sslproto.py", line 529, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "C:\Program Files (x86)\Python38-32\lib\asyncio\sslproto.py", line 189, in feed_ssldata
self._sslobj.do_handshake()
File "C:\Program Files (x86)\Python38-32\lib\ssl.py", line 944, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1108)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Simon\Desktop\Venv\bot.py", line 19, in <module>
client.run(token)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\client.py", line 640, in run
return future.result()
File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\client.py", line 621, in runner
await self.start(*args, **kwargs)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\client.py", line 584, in start
await self.login(*args, bot=bot)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\client.py", line 442, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\http.py", line 261, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\http.py", line 165, in request
async with self.__session.request(method, url, **kwargs) as r:
File "C:\Program Files (x86)\Python38-32\lib\site-packages\aiohttp\client.py", line 1012, in __aenter__
self._resp = await self._coro
File "C:\Program Files (x86)\Python38-32\lib\site-packages\aiohttp\client.py", line 480, in _request
conn = await self._connector.connect(
File "C:\Program Files (x86)\Python38-32\lib\site-packages\aiohttp\connector.py", line 523, in connect
proto = await self._create_connection(req, traces, timeout)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\aiohttp\connector.py", line 858, in _create_connection
_, proto = await self._create_direct_connection(
File "C:\Program Files (x86)\Python38-32\lib\site-packages\aiohttp\connector.py", line 1004, in _create_direct_connection
raise last_exc
File "C:\Program Files (x86)\Python38-32\lib\site-packages\aiohttp\connector.py", line 980, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "C:\Program Files (x86)\Python38-32\lib\site-packages\aiohttp\connector.py", line 938, in _wrap_create_connection
raise ClientConnectorCertificateError(
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host discordapp.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1108)')]
I am using the basic code from the discord.py internet page:
import discord
client = discord.Client()
token = 'Token'
#client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
client.run(token)
I already tried certain solutions of my own and from the internet, non of which seemed to work.
Thanks for every help in Advance!
Simon
It was quite an easy fix:
Open IE as Admin
Open Discord.com and click on the lock in the tab bar
Install the certificate and done
So I am using Pycharm, installed the discord.py and asyncio libraries in project interpreter. And I basically followed this video on Youtube: https://www.youtube.com/watch?v=D-7zuNRjqhw&t=190s
I have also tried other approaches like using atom which didn't work because of the python 3.7 and asyncio error.
If anyone can tell me what's going on that would be great or any other way to make a python discord bot, I am open to ideas.
the code:
import discord
import asyncio
from discord.ext import commands
client = commands.Bot(command_prefix="!")
#client.event
async def on_ready():
print("hello")
#client.command(pass_context=True)
async def ping(str):
await client.say("pong")
client.run("NTU3MjU2MTc5NTQyMTMwNzA5.D3FpXQ.QpSaso3vStRTet1m8CT8GYAJMvM")
and if I ran this code then it will return these error messages.
/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/bin/python /Users/SoyMilkFrank/PycharmProjects/untitled13/main.py
Traceback (most recent call last):
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 601, in _create_direct_connection
local_addr=self._local_addr)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 809, in create_connection
sock, protocol_factory, ssl, server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 835, in _create_connection_transport
yield from waiter
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py", line 505, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py", line 201, in feed_ssldata
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 304, in connect
yield from self._create_connection(req)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 578, in _create_connection
transport, proto = yield from self._create_direct_connection(req)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 624, in _create_direct_connection
(req.host, req.port, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 1] Can not connect to discordapp.com:443 [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/main.py", line 15, in <module>
client.run("NTU3MjU2MTc5NTQyMTMwNzA5.D3FpXQ.QpSaso3vStRTet1m8CT8GYAJMvM")
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/client.py", line 519, in run
self.loop.run_until_complete(self.start(*args, **kwargs))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 473, in run_until_complete
return future.result()
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/client.py", line 490, in start
yield from self.login(*args, **kwargs)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/client.py", line 416, in login
yield from getattr(self, '_login_' + str(n))(*args, **kwargs)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/client.py", line 346, in _login_1
data = yield from self.http.static_login(token, bot=is_bot)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/http.py", line 258, in static_login
data = yield from self.request(Route('GET', '/users/#me'))
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/http.py", line 137, in request
r = yield from self.session.request(method, url, **kwargs)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/client.py", line 555, in __iter__
resp = yield from self._coro
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/client.py", line 198, in _request
conn = yield from self._connector.connect(req)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 314, in connect
.format(key, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 1] Cannot connect to host discordapp.com:443 ssl:True [Can not connect to discordapp.com:443 [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)]]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10f6805c0>
Process finished with exit code 1
First of all do you need:
#client.command(pass_context = True)
Just replace it with:
#client.command()
Next for the ping function:
async def ping(ctx):
await ctx.send("Pong!")
Hope this helps, if you need any extra help join the Discord API Discord server. Also make sure you have the latest version of discord.py using pip