slackapi/python-slack-sdk

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>

JohnHamlett opened this issue · 1 comments

We are migrating to a new server, we are getting the following error when we try to post a message to slack

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>

Reproducible in:

from slack_sdk import WebClient

token = "xoxb-xxxxxxxxxxxxxxxxxxxx"
slack = WebClient(token=token)
message = {"channel": "test", "text": "test"}
slack.chat_postMessage(**message)

The Slack SDK version

PS C:\BuildAgent\bin> pip show slack_sdk
Name: slack-sdk
Version: 3.22.0
Summary: The Slack API Platform SDK for Python
Home-page: https://github.com/slackapi/python-slack-sdk
Author: Slack Technologies, LLC
Author-email: opensource@slack.com
License: MIT
Location: c:\program files\python310\lib\site-packages
Requires:
Required-by: slack-bolt

Python runtime version

Python 3.10.11

OS info

Windows Server 2022

Expected result:

The request is sent to Slack

Actual result:

Full stack trace:

PS C:\BuildAgent\bin> python C:\Users\Administrator\Desktop\slack.py
Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\urllib\request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Program Files\Python310\lib\http\client.py", line 1276, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files\Python310\lib\http\client.py", line 1322, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python310\lib\http\client.py", line 1271, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python310\lib\http\client.py", line 1031, in _send_output
    self.send(msg)
  File "C:\Program Files\Python310\lib\http\client.py", line 969, in send
    self.connect()
  File "C:\Program Files\Python310\lib\http\client.py", line 1448, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "C:\Program Files\Python310\lib\ssl.py", line 512, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Program Files\Python310\lib\ssl.py", line 1070, in _create
    self.do_handshake()
  File "C:\Program Files\Python310\lib\ssl.py", line 1341, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\slack.py", line 10, in <module>
    slack.chat_postMessage(**message)
  File "C:\Program Files\Python310\lib\site-packages\slack_sdk\web\client.py", line 2476, in chat_postMessage
    return self.api_call("chat.postMessage", json=kwargs)
  File "C:\Program Files\Python310\lib\site-packages\slack_sdk\web\base_client.py", line 156, in api_call
    return self._sync_send(api_url=api_url, req_args=req_args)
  File "C:\Program Files\Python310\lib\site-packages\slack_sdk\web\base_client.py", line 187, in _sync_send
    return self._urllib_api_call(
  File "C:\Program Files\Python310\lib\site-packages\slack_sdk\web\base_client.py", line 294, in _urllib_api_call
    response = self._perform_urllib_http_request(url=url, args=request_args)
  File "C:\Program Files\Python310\lib\site-packages\slack_sdk\web\base_client.py", line 495, in _perform_urllib_http_request
    raise err
  File "C:\Program Files\Python310\lib\site-packages\slack_sdk\web\base_client.py", line 397, in _perform_urllib_http_request
    resp = self._perform_urllib_http_request_internal(url, req)
  File "C:\Program Files\Python310\lib\site-packages\slack_sdk\web\base_client.py", line 526, in _perform_urllib_http_request_internal
    resp = urlopen(req, context=self.ssl, timeout=self.timeout)  # skipcq: BAN-B310
  File "C:\Program Files\Python310\lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Program Files\Python310\lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
  File "C:\Program Files\Python310\lib\urllib\request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Program Files\Python310\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "C:\Program Files\Python310\lib\urllib\request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "C:\Program Files\Python310\lib\urllib\request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Hi, @JohnHamlett! Thanks for the question! 🙌

On searching the error, it looks like it might be an issue with your certificate configuration on your machine with running Python rather than the SDK itself. This error can be thrown if your cert store is outdated or you're behind a firewall/proxy. I recommend checking your certificates on your machine to make sure they are valid and configured properly.