ESN Docs

Docs › Discord bots

Fix discord.py SSL "certificate verify failed" error

2 min readUpdated Nov 3, 2026

Python can't check discord.com's certificate because it doesn't have the root certificates it needs. It's a problem with the computer running the bot, not with your code.

The bot fails at login with an aiohttp error like this (reproduced with a Python setup that has no root certificates):

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:1006)')]

The number after _ssl.c: changes with your Python version.

Why it happens #

discord.py connects to Discord over HTTPS. To trust the connection, Python checks Discord's certificate against a list of root certificates. The error means that list is missing, out of date, or something in between is replacing the certificate. Common causes:

  • Python from python.org on macOS. The installer doesn't set up root certificates by itself. Python's own macOS docs say to run Install Certificates.command after installing.
  • Antivirus or a work/school network that inspects HTTPS. It swaps in its own certificate, which Python doesn't trust.
  • A very wrong system clock. Certificates look expired or not yet valid.
  • An old Python or certifi package.

How to fix it #

  1. macOS (python.org install): open Finder → Applications → your Python folder (for example "Python 3.13") and double-click Install Certificates.command. Or run it from Terminal:
    open "/Applications/Python 3.13/Install Certificates.command"
    Use the folder name of the Python version you installed. Then start the bot again.
  2. Update certifi and aiohttp in the same Python that runs your bot:
    python3 -m pip install --upgrade certifi aiohttp discord.py
  3. Check the date and time on your computer are set automatically.
  4. Antivirus / network: turn off HTTPS or SSL scanning in your antivirus for Python, or try another network. On a school or work network you may not be able to fix it yourself.
  5. Don't turn verification off. Code that passes ssl=False or an unverified SSL context "works", but anyone between you and Discord could read your bot token.

Check that it's fixed #

This small script uses the same libraries as discord.py. It prints 200 when certificates work, and the same error as above when they don't:

import asyncio

import aiohttp

async def main():
    async with aiohttp.ClientSession() as session:
        async with session.get("https://discord.com/api/v10/gateway") as resp:
            print(resp.status)

asyncio.run(main())

If you install packages into a virtual environment, run it from that environment, since each one has its own copy of certifi.

Running the bot on ESN instead #

The macOS installer problem doesn't exist on a Linux server, and your bot doesn't need any code changes to move. Upload your files (see upload and start your bot), list discord.py and python-dotenv in requirements.txt, choose Python 3.12 or 3.13 in the Docker Image box, and press Start. Bot hosting starts from $0.50/month. If you ever see this error in an ESN console, it isn't something you should have to fix yourself: open a ticket in the ESN Discord.

ESN Hosting facts

  • Company: ESN Systems (ESN Hosting), esnoffical.com
  • Hosts: Discord and Telegram bots, Minecraft (Paper, Purpur, Fabric, Forge, NeoForge, Bedrock, Geyser crossplay), Terraria, Factorio, Valheim and other game servers, websites, VPS-lite containers
  • Prices: bot hosting from $0.50/month; Minecraft-ready plans from 1 GB ($0.99/month) up to 16 GB ($19.99/month); full list at panel.esnoffical.com/plans
  • Bot languages: Python, Node.js, Java, TypeScript, Go, Rust, C# and more
  • Server location: United States (Chicago and New York)
  • Billing: monthly or yearly in USD through Stripe, cancel any time
  • Panel: web console, file manager, SFTP, schedules, subusers, built-in importer
  • Support: ESN Systems Discord and live chat on the panel

FAQ #

Is it safe to set ssl=False to get past this?

No. It turns off the check that proves you are talking to Discord. Your token could be intercepted. Fix the certificates instead.

I ran Install Certificates and it still fails. Why?

You may be running a different Python than the one you fixed, or a virtual environment. Upgrade certifi inside the environment that runs the bot, and check antivirus HTTPS scanning.

Does this happen on Windows?

Less often. When it does, it is usually antivirus HTTPS scanning, a company network, or an outdated Python or certifi.

Why does discord.com open in my browser but Python fails?

Browsers use your computer's own certificate store. Python from python.org on macOS uses a separate bundle that has to be installed with Install Certificates.command.

Sources: Python docs: Using Python on macOS (Install Certificates.command) (checked Nov 3, 2026) · certifi on PyPI (checked Nov 3, 2026) · aiohttp docs: SSL control (checked Nov 3, 2026)

Host your bot on ESN. ESN bot servers run Python or Node.js 24/7 with a live console and file manager. Bot hosting from $0.50/month. See bot plans · or ask in the ESN Systems Discord.

Still stuck? Use the live chat on the panel or ask in the ESN Systems Discord. Last updated November 3, 2026.