Solveddiscord.py Cannot connect to host discordapp.com certificate verify failed

Hey guys

So I've just started trying to learn to build a Discord bot today but ran into this issue that's preventing me from running my bot.

I have installed Python 3.6 and the latest version of discord.py. I ran into this SSL certificate issue when I tried to run my bot, which is only a couple of lines.

import stuff...

token = 'my bot token here'
client = discord.Client()
client.run(token)

Instead of logging my bot in, I get the following error messages:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/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 802, 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 828, in _create_connection_transport
yield from waiter
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py", line 503, 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 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 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/connector.py", line 304, in connect
yield from self._create_connection(req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/connector.py", line 578, in _create_connection
transport, proto = yield from self._create_direct_connection(req)
File "/Library/Frameworks/Python.framework/Versions/3.6/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:749)]

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

Traceback (most recent call last):
File "/Users/lcheng15/Dropbox/DiscordBot/DiscordBot.py", line 14, in
client.run(token)
File "/Library/Frameworks/Python.framework/Versions/3.6/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 466, in run_until_complete
return future.result()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/client.py", line 490, in start
yield from self.login(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/client.py", line 416, in login
yield from getattr(self, 'login' + str(n))(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/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 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/http.py", line 195, in static_login
data = yield from self.get(self.ME)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/http.py", line 105, in request
r = yield from self.session.request(method, url, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client.py", line 555, in iter
resp = yield from self._coro
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client.py", line 198, in _request
conn = yield from self._connector.connect(req)
File "/Library/Frameworks/Python.framework/Versions/3.6/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:749)]]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x105cb2e80>

I have found others with the same error on the MusicBot's GitHub. They solved it by installing a certificate, which did not solve my problem. BTW, I'm running MacOS Sierra

I would really appreciate it if you guys could give me some help here. It's really frustrating when the first basic step fails. Thanks in advance!

12 Answers

✔️Accepted Answer

Rapptz
1018

I looked into this some more. Apparently 3.6 changed the installation process on OS X.

When you install there's this piece of information:

macOS users: If you are using the Python 3.6 from the python.org binary installer linked on this page, please carefully read the Important Information displayed during installation; this information is also available after installation by clicking on /Applications/Python 3.6/ReadMe.rtf. There is important information there about changes in the 3.6.0 installer-supplied Python, particularly with regard to SSL certificate validation.

When you head over to the ReadMe.rtf file you get more information as well:

Certificate verification and OpenSSL
--
NEW This variant of Python 3.6 now includes its own private copy of OpenSSL 1.0.2. Unlike previous releases, the deprecated Apple-supplied OpenSSL libraries are no longer used. This also means that the trust certificates in system and user keychains managed by the Keychain Access application and the security command line utility are no longer used as defaults by the Python ssl module. For 3.6.0, a sample command script is included in /Applications/Python 3.6 to install a curated bundle of default root certificates from the third-party certifi package (https://pypi.python.org/pypi/certifi). If you choose to use certifi, you should consider subscribing to the project's email update service to be notified when the certificate bundle is updated.
--
The bundled pip included with the Python 3.6 installer has its own default certificate store for verifying download connections.

Basically navigate to your Applications/Python 3.6/ folder and double click the Install Certificates.command.

Kind of a headache on the python dev group but also a pain from Apple's POV for providing deprecated binaries.

Other Answers:

Can confirm @ButterCheezii 's statement on my end. Using Python 3.6.0 in PyCharm (and terminal) on 10.10.5 resulted in the same error. Converting the project over to Python 3.5.2 fixed the issue. Didn't have to install a certificate or anything. Still trying to decide whether to use Heroku or pay $3 bucks a month for a VPS from OVH.

@Rapptz It may be worth mentioning this in the README

Please don't necro old Github issues.

This is more a question for the official help server.

To answer your question however: the certificate can be located here. Please download and install the certficate and restart your bot.

also, a location of the download link.

How i install certificate command file in windows 10?

Yeah, I believe the macOS version of python 3.6 is fucked. You might have to stick with a linux or windows machine because all that I've seen doesn't work on my machine (that has the same issue). I have a VPS so it's not much of a problem anyway, but just a heads up.

Related Issues:

277
discord.py Cannot connect to host discordapp.com certificate verify failed
I looked into this some more Apparently 3.6 changed the installation process on OS X ...
11
discord.py ImportError: No module named 'discord'
python3 -m pip install discord.py I have installed the module for discord properly using python3.5 b...
264
tqdm Jupyterlab and tqdm_notebook
I confirm this problem on my environment but it is upstream so IMHO nothing can be done on tqdm Plea...
57
discord api docs Slash Command Permissions
Okay I think it's important to differentiate between public and private Discord bots in this convers...
56
discord.js Slash Commands Support
Documentation has been released on the developer docs! https://discord.com/developers/docs/interacti...
53
community edition MS Teams don't work
As a quick and dirty hack: edit the service open the “Advanced” section Seeing error when trying to ...
47
tqdm How to update single progress bar in multiprocessing map()
from https://stackoverflow.com/questions/41920124/multiprocessing-use-tqdm-to-display-a-progress-bar...
30
discord.js Mocking Discord JS for Unit Testing
It is actually possible to mock discord.js data without relying on Discord API (at least for my use-...
23
discord.js guildMemberSpeaking event no longer working?
We (discord) now only send speaking event once per WS connection - as our clients dont need this eve...
21
discord.js Unhandled error on close
Handle the error event of your client Something simple like client.on('error' console.error); would ...
15
discord api docs [API] Bot MFA/Two Factor
Self bots aren't supported You shouldn't be going through the 2FA login flow on your bot either Log ...
15
discord.js Structures
You install a library that overrides a class's send method to add internal tracking for auto-editabl...
14
discord.js Error: Members didn't arrive in time.
As of 27/10/2020 (warned since October 7 2020) Discord bot not caching all members and giving wrong ...
14
discord.js Timeout - Shards With Unavailable Guilds Not Starting
I fixed this problem for my shard.js 😇🥳 Please describe the problem you are having in as much deta...
14
tqdm tqdm.pandas() ImportError: cannot import 'PanelGroupBy'
should be fixed in tqdm>=4.23.4 When using tqdm v4.23.3 and pandas v0.23.0 I get this error: It look...
13
discord.js playFile/playStream fails to play short (<1 sec) files
Really happy to announced this is finally fixed on the indev-prism branch! 🎉 While this isn't compl...
11
discord.js V12 Master Receiver not Decoding Opus
I figured it out! For the latest master: In src/client/voice/receiver/PacketHandler.js at L66 Replac...
10
tqdm Wrong output in Windows console
That's partial unicode support You can probably fix it with tqdm(... ascii=True) ...
5
community edition Whatsapp Error (Needs Chrome 36+)
So here is a workaround using a custom service: Step 1 Create Custom service Step 2 Name: Whatever U...
4
discord api docs "Message is empty" error for some UTF8 characters sent in content of webhook
Definitely not valid JSON.. Please use a proper JSON encoder It really looks like you're trying to b...
4
discord.js Guild returns empty collections (members, roles, channels etc.)
Anything that comes in nested objects (channels members etc.) is an empty collection The output you ...
3
BetterDiscordApp A better installer for linux?
https://aur.archlinux.org/cgit/aur.git/tree/betterdiscordctl?h=betterdiscord-rauenzi-git is a script...
926
keras Loading model with custom loss function: ValueError: 'Unknown loss function'
I solved this problem by adding 'custom_bojects' my loss function: I trained and saved a model that ...
731
scrapy ' error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 '
@euler16 for scrapy with Python 3 you'll need with Python 2 you'll need I wanted to install scrapy i...
633
keras Tensorflow backend - bug in model._make_predict_function(...)
I had this problem when doing inference in a different thread than where I loaded my model ...
575
mysqlclient Can't install mysqlclient on MacOS
You can set ssl library path explicitly. Hi I'm on MacOSX Sierra ...
516
keras Creating Model variable throws "AttributeError: 'Tensor' object has no attribute '_keras_history'"
@zaid478 oh I assumed you were doing it on coursera Anyway Hello all setup: Keras 2.0 Tensorflow 1.0...
456
tensorflow ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
@rhinsall I just found this out myself not sure if it's common knowledge but got around this by doin...
423
ipython Last jedi release (0.18.0) is incompatible with ipython (7.19 and 7.18 tested); reason - column arg was deprecated, and now removed
As a temporary fix for anyone just trying to get things working again: It would be really nice if yo...
416
pyodbc pip install pyodbc failing: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory #include <sql.h> ^ Your machine do...
395
keras "<tensor> is not an element of this graph." when loading model.
I had a problem similar to that of @piraka9011 which was solved by calling model._make_predict_funct...
392
psycopg2 psycopg2-binary fails to install on macOS Big Sur 11.0.1 and Python 3.9.0 (with possible workaround)
Actually figured it out Haven't worked on a Mac in a while and forgot about the PostgreSQL dependenc...
387
pytorch I can't import PyTorch, libomp.dylib can't be loaded.
brew install libomp solves the problem. 🐛 Bug I tried to install PyTorch but I can't use it ...
380
pytorch RuntimeError: cuda runtime error (59) : device-side assert triggered when running transfer_learning_tutorial
@soumith Hi I find the error it is due to my labels contain value -1 which is unacceptable in criter...
373
Zappa bad magic number in 'application': b'\x03\xf3\r\n': ImportError
I was able to fix this too by doing find -name \*.pyc -delete Mine definitely wasn't caused by PY2 -...
356
tensorflow At Runtime : "Error while reading resource variable softmax/kernel from Container: localhost"
I had the same issue in tensorflow 1.13.1 which I have resolved by creating a reference to the sessi...
355
tensorflow Mac + Python 3.6.1: Attempting to download mnist data results in CERTIFICATE_VERIFY_FAILED error
This might have also been because I recently switched to a new machine and it's still only partially...
335
pyenv WARNING: pyenv init - no longer sets PATH.
I saw the same message on an RH derivative Linux using bash 4.4.19 To resolve After running pyenv up...
333
pyenv unable to install python 3.8.0 on macox 11
Try to install brew reinstall zlib bzip2 and in the ~/.zshrc file add the following: in case you are...
331
psutil psutil fails to install on python3.6 and Ubuntu16.04
I was just about to comment the same after I read the install file: https://github.com/giampaolo/psu...
326
psycopg2 Installing psycopg2-binary with Python:3.6.4-alpine doesn't work
I found this solution which worked quite fine Edit The above compiles the package from source so I w...
325
pyenv Unable to build Python on macOS Big Sur with Xcode 12 beta
Thank you HomeBrew team for all the hard work you did to find the patch that python team is brewing ...
320
Pillow ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (unknown location)
I'm getting the same error right now after conda install pillow on Win 10 It installed pillow 6.2.1 ...
317
pip ImportError in system pip wrappers after an upgrade
I followed some instructions elsewhere and ran and hit upon this issue fixed it returning me to the ...
308
tensorflow UnrecognizedFlagError: Unknown command line flag 'f'
I solved this issue by adding the line: tf.app.flags.DEFINE_string('f' '' 'kernel') what this essent...
298
tensorflow FutureWarning: Deprecated numpy API calls in tf.python.framework.dtypes
@Akeaakar And for the time being pip install numpy<1.17 to revert to numpy version 1.16.4 ...
295
certbot Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA
Unfortunately My operating system is (include version): Ubuntu 16.04 I installed Certbot with (certb...
293
pyinstaller TypeError: an integer is required (got type bytes) when compiling any script
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz Direct install the lat...
287
readthedocs.org Sphinx error: master file [..]/checkouts/latest/contents.rst not found
Encountered the same problem here I'm using sphinx 2.0.1 I’m still new to readthedocs.org and have n...