Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3 & Slack Client : ssl.SSLCertVerificationError

I'm trying to access Slack in python 3.8 but i'm unable to pass the first step. Here is my code :

import slack

slack_token="xoxp-*******-*******-*******-*******"
client = slack.WebClient(slack_token)

client.chat_postMessage(
    channel="XXXXXXXXXX",
    text="Hello from your app! :tada:"
)

print('hello')

and here is the error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 1046, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 1076, in _create_connection_transport
    await waiter
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/sslproto.py", line 529, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 944, in do_handshake
    self._sslobj.do_handshake()
  ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)

venv config:

pip3 freeze
aiohttp==3.6.2
async-timeout==3.0.1
attrs==19.3.0
certifi==2019.11.28
chardet==3.0.4
idna==2.8
multidict==4.7.4
pipenv==2018.11.26
slack==0.0.2
slackclient==2.5.0
virtualenv==16.7.9
virtualenv-clone==0.5.3
yarl==1.4.2
like image 983
JFMarquis Avatar asked Jan 19 '20 08:01

JFMarquis


People also ask

What is Python 3?

What is Python 3? Python 3 is a newer version of the Python programming language which was released in December 2008. This version was mainly released to fix problems that exist in Python 2. The nature of these changes is such that Python 3 was incompatible with Python 2. It is backward incompatible.

Can I download Python 3?

Python 3 can be installed using the official Python 3 installer. Go to the Python Releases for Mac OS X page and download the latest stable release macOS 64-bit/32-bit installer. After the download is complete, run the installer and click through the setup steps leaving all the pre-selected installation defaults.

Is Python 3 a programming language?

Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming.

Why we should use Python 3?

Python 3 has an easier syntax compared to Python 2. A lot of libraries of Python 2 are not forward compatible. A lot of libraries are created in Python 3 to be strictly used with Python 3. Python 2 is no longer in use since 2020.


1 Answers

Following instruction worked for me:

import ssl
import certifi
ssl_context = ssl.create_default_context(cafile=certifi.where())
client = slack.WebClient(token=os.environ['SLACK_TOKEN'], ssl=ssl_context)
like image 184
mohammad mahdi mohajer Avatar answered Sep 28 '22 07:09

mohammad mahdi mohajer