I am currently working on coding a simple chat bot application for a slack workspace that I created. I followed a simple tutorial on youtube at the following link: https://www.youtube.com/watch?v=KJ5bFv-IRFM&ab_channel=TechWithTim
Essentially, here are the steps that I followed:
- Create workspace
- Go to slack api website and click on “Your Apps” in top right hand corner and create app in respective workspace
- Add chat:write OAuth Scope for bot token scope
- Install to workspace and copy corresponding workspace token
- Create two new files in VSCode: bot.py and .env
- In .env, add copied slack token into a variable
- import libraries, modules, API etc. in bot.py file (code supplied below)
- Connect app to "chat-bot" channel
Here is the code for my bot.py file:
import os
from pathlib import Path
from dotenv import load_dotenv # loads environment variable file
env_path = Path('.') / '.env' # tells the system where our environment file is located
load_dotenv(dotenv_path=env_path)
client = slack.WebClient(token=os.environ['SLACK_TOKEN']) # didn't get an autocomplete for WebClient
client.chat_postMessage(channel='#chat-bot', text="Hello World")
Code to .env file which is in the same directory as my bot.py file:
SLACK_TOKEN= (my slack token that I copied from settings)
The problem arises when I type the client.chat_postMessage(channel='#chat-bot', text="Hello World")
line of code. I get an error that tells me that my SSL certificate verify failed. Specifically the error that is generated states: urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)>
I have already tried a couple of posted solutions such as...
- Tried installing /Applications/Python\ 3.9/Install\ Certificates.command but it told me that the requirement is already satisfied
- Downgraded webhook to version 0.47.0 as referenced by this post: https://github.com/slackapi/python-slack-sdk/issues/334 I am unable to find anymore solutions to this problem.
If you happen to know what may be causing the issue any insight will be helpful. FYI, I am running the script bot.py using python3 bot.py.