SSL证书问题与Python Slack机器人

huangapple go评论68阅读模式
英文:

SSL Certificate Issue w/ Python Slack Bot

问题

I am attempting to write a simple Slack both in Python, but am unable to connect because of an SSL issue. This has rendered all examples from tutorials I've found nonfunctional. I have also attempted several iterations on the solution using certifi as suggested in this post with no luck.

Here is the relevant code:

import slack
import os
from pathlib import Path
from dotenv import load_dotenv

import ssl
import certifi
ssl_context = ssl.create_default_context(cafile=certifi.where())

env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)

client = slack.WebClient(token=os.environ['SLACK_TOKEN'], ssl=ssl_context)
client.chat_postMessage(channel='#bot-channel', text='Hello World!')

And the error message:

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)>

Python version is 3.10.5

英文:

I am attempting to write a simple Slack both in Python, but am unable to connect because of an SSL issue. This has rendered all examples from tutorials I've found nonfunctional. I have also attempted several iterations on the solution using certifi as suggested in this post with no luck.

Here is the relevant code:

import slack
import os
from pathlib import Path
from dotenv import load_dotenv

import ssl
import certifi
ssl_context = ssl.create_default_context(cafile=certifi.where())

env_path = Path(&#39;.&#39;) / &#39;.env&#39;
load_dotenv(dotenv_path = env_path)

client = slack.WebClient(token = os.environ[&#39;SLACK_TOKEN&#39;], ssl = ssl_context)
client.chat_postMessage(channel = &#39;#bot-channel&#39;, text = &#39;Hello World!&#39;)

And the error message:

urllib.error.URLError: &lt;urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)&gt;

Python version is 3.10.5

答案1

得分: 1

slackclient 已被弃用。您应该改用新的 slack_sdk。新的 SDK 似乎不需要 SSL 证书,因此完全避免了这个问题。

英文:

slackclient is deprecated. You should use the new slack_sdk instead. The new sdk does not seem to require an SSL cert, so this issue is avoided entirely.

huangapple
  • 本文由 发表于 2023年6月4日 23:37:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76401170.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定