I wrote a simple Discord Bot in Python and I compiled it as an app for distribution on MacOS using PyInstaller. When my users ran it they got the following error:

An error occurred: Cannot connect to host discord.com:443 - ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

Below is the code for the bot:

import discord
from discord.ext import commands

def launch_bot(token):    

    intents = discord.Intents.all()
    intents.message_content = True
    # client = commands.Bot(command_prefix = '?', description=description, intents=intents)
    # #client = discord.Client(intents=intents) 

    client = discord.Client(intents=intents)

    @client.event
    async def on_ready():
        print('Logged in as')
        print(client.user.name)
        print(client.user.id)
        print('------')

        print_to_textbox('Logged in as')
        print_to_textbox(str(client.user.name))
        print_to_textbox(str(client.user.id))
        print_to_textbox('------')
        print_to_textbox('Now go to Discord and type ?react in the channel you want to react to all messages in.')

    try:
        client.run(token) 
    except Exception as e:
        logging.exception("An error occurred") 

What I have tried:

A fix seems to be to download and install Python and run the "Install Certificate.command" file to install the latest certificates. However, I would ideally not want the end user to have to do this to use the application as majority of them are non-technical. Is there a way to make sure the latest certificates are shipped with the compiled MacOS app? I have pip installed certifi in my virtual environment before compiling and building the app so it should have the latest version of the certifi Python module but that does not prevent this issue from occuring.

Thanks for your help.

1

There are 1 best solutions below

2
On

Found the issue (and the resolution) on the project's github site. I know that the general issue is from Windows OS, but in the comments you can find the MacOS solution as well.