SSL certificate verify failure when trying to run Bolt Python Slack app. (expired certificate)

71 Views Asked by At

When trying to run the app to test if the event listener is working properly (python app.py in the terminal), it will output that the Bolt app is running, but then immediately follow up with 'Failure to establish connection (session_id= .....)' and states SSL: CERTIFICATE_VERIFY_FAILED. Here is my code:

import os
import slack
import ssl
from pathlib import Path
from dotenv import load_dotenv
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler

ssl._create_default_https_context = ssl._create_unverified_context

# Initialize the app and retrieve tokens
env_path = Path('.')/'.env'
load_dotenv(dotenv_path=env_path)

# client connects to the Slack API and allows use of the SDK
client = slack.WebClient(token=os.environ['SLACK_BOT_TOKEN'])

# app allows the bot to listen to events in Slack
app = App(token=os.environ['SLACK_BOT_TOKEN'])

@app.message("Are you listening?")
def response(message, say): # say sends a message to the channel where the event was triggered
    say(f"Yes, <@{message['user']}>")

if __name__ == "__main__":
    SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()

When running the app, this is the output:

Failed to establish a connection (session id: 105eefb9-3711-4734-91ad-4b3a0773778e, error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007))
on_error invoked (session id: None, error: SSLCertVerificationError, message: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007))
Bolt app is running!
Failed to establish a connection (session id: b0d583f3-fe0c-4d45-ae2c-07609ad8ad8e, error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007))
on_error invoked (session id: 105eefb9-3711-4734-91ad-4b3a0773778e, error: SSLCertVerificationError, message: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007))
0

There are 0 best solutions below