Adding a custom CA using python 3.6 (Anaconda) in Windows 10 is not working. What I did:
Created 2 environment variables:
SSL_CERT_DIR=C:\_Data\Certs <-- This alone should do the trick
SSL_CERT_FILE=C:\_Data\Certs\burp
I'm running Burp on localhost. I've exported the CA cert to c:\_Data\Certs\burp. Tried PEM and DER, both should work.
My program:
import aiohttp
import ssl
import asyncio
async def main():
session = aiohttp.ClientSession()
print(ssl.get_default_verify_paths()) # to verify that my environment variable is working
f = open('C:\\_Data\\Certs\\burp', 'r') # To check I don't have a permission problem
f.close()
aiohttp_proxy = 'http://127.0.0.1:8080'
async with session.get('https://www.whatismyip.com', proxy=aiohttp_proxy) as response:
print(await response.text())
await session.close()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Output:
DefaultVerifyPaths(cafile='C:\\_Data\\Certs\\burp', capath='C:\\_Data\\Certs', openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='/usr/local/ssl/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='/usr/local/ssl/certs')
Traceback (most recent call last):
File "C:\Users\defaultuser\PycharmProjects\testproject\venv\lib\site-packages\aiohttp\connector.py", line 822, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs)
File "C:\ProgramData\Anaconda3\Lib\asyncio\base_events.py", line 802, in create_connection
sock, protocol_factory, ssl, server_hostname)
File "C:\ProgramData\Anaconda3\Lib\asyncio\base_events.py", line 828, in _create_connection_transport
yield from waiter
File "C:\ProgramData\Anaconda3\Lib\asyncio\sslproto.py", line 503, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "C:\ProgramData\Anaconda3\Lib\asyncio\sslproto.py", line 201, in feed_ssldata
self._sslobj.do_handshake()
File "C:\ProgramData\Anaconda3\Lib\ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/defaultuser/PycharmProjects/testproject/_test/test_cert.py", line 20, in <module>
loop.run_until_complete(main())
File "C:\ProgramData\Anaconda3\Lib\asyncio\base_events.py", line 466, in run_until_complete
return future.result()
File "C:/Users/defaultuser/PycharmProjects/testproject/_test/test_cert.py", line 14, in main
async with session.get('https://www.whatismyip.com', proxy=aiohttp_proxy) as response:
File "C:\Users\defaultuser\PycharmProjects\testproject\venv\lib\site-packages\aiohttp\client.py", line 843, in __aenter__
self._resp = await self._coro
File "C:\Users\defaultuser\PycharmProjects\testproject\venv\lib\site-packages\aiohttp\client.py", line 366, in _request
timeout=timeout
File "C:\Users\defaultuser\PycharmProjects\testproject\venv\lib\site-packages\aiohttp\connector.py", line 445, in connect
proto = await self._create_connection(req, traces, timeout)
File "C:\Users\defaultuser\PycharmProjects\testproject\venv\lib\site-packages\aiohttp\connector.py", line 754, in _create_connection
req, traces, timeout)
File "C:\Users\defaultuser\PycharmProjects\testproject\venv\lib\site-packages\aiohttp\connector.py", line 960, in _create_proxy_connection
req=req)
File "C:\Users\defaultuser\PycharmProjects\testproject\venv\lib\site-packages\aiohttp\connector.py", line 827, in _wrap_create_connection
raise ClientConnectorSSLError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorSSLError: Cannot connect to host www.whatismyip.com:443 ssl:None [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001C3E504F278>
Process finished with exit code 1
I've doublechecked the CA file is correct by opening it and verifying it's the same as when pointing a regular browser to my proxy running at localhost and verifying the CA details after accessing an HTTPS website.
Why isn't it working ?
Reinstalled Anaconda, updated Pycharm, regenerated the CA in Burp and rebooted, it now works. Not sure what was the cause.
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 was playing with some web frameworks for Python, when I tried to use the framework aiohhtp with this code (taken from the documentation):
import aiohttp
import asyncio
#********************************
# a solution I found on the forum:
# https://stackoverflow.com/questions/50236117/scraping-ssl-certificate-verify-failed-error-for-http-en-wikipedia-org?rq=1
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
# ... but it doesn't work :(
#********************************
async def main():
async with aiohttp.ClientSession() as session:
async with session.get("https://python.org") as response:
print("Status:", response.status)
print("Content-type:", response.headers["content-type"])
html = await response.text()
print("Body:", html[:15], "...")
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
When I run this code I get this traceback:
DeprecationWarning: There is
no current event loop
loop = asyncio.get_event_loop()
Traceback (most recent call last):
File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 986, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
File "c:\Python310\lib\asyncio\base_events.py", line 1080, in create_connection
transport, protocol = await self._create_connection_transport(
File "c:\Python310\lib\asyncio\base_events.py", line 1110, in _create_connection_transport
await waiter
File "c:\Python310\lib\asyncio\sslproto.py", line 528, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "c:\Python310\lib\asyncio\sslproto.py", line 188, in feed_ssldata
self._sslobj.do_handshake()
File "c:\Python310\lib\ssl.py", line 974, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\chris\Documents\Programmi_in_Python_offline\Esercitazioni\Python_commands\aioWebTest.py", line 21, in <module>
loop.run_until_complete(main())
File "c:\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete
return future.result()
File "c:\Users\chris\Documents\Programmi_in_Python_offline\Esercitazioni\Python_commands\aioWebTest.py", line 12, in main
async with session.get("https://python.org") as response:
File "c:\Python310\lib\site-packages\aiohttp\client.py", line 1138, in __aenter__
self._resp = await self._coro
File "c:\Python310\lib\site-packages\aiohttp\client.py", line 535, in _request
conn = await self._connector.connect(
File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 542, in connect
proto = await self._create_connection(req, traces, timeout)
File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 907, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 1206, in _create_direct_connection
raise last_exc
File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 1175, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 988, in _wrap_create_connection
raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host python.org:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)')]
From the final row I have thought that it was a problem with a certificate that is expired, so I searched on the internet and I tried to solve installing some certificates:
COMODO ECC Certification Authority;
three certificates that I took from the site www.python.org under Bango's advice for the question:
I'm sorry for the long question, but I searched a lot on the internet and I couldn't find the solution for my case.
Thank you in advance, guys <3
Picking up on the comment by #salparadise, the following worked for me:
session.get("https://python.org", ssl=False)
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.
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!
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