pythonsslpip

Getting CERTIFICATE_VERIFY_FAILED when trying to use slackclient and python 2.7


My setup is Mac OS 10.13.6 (Updated), python 2.7.15 and I'm connected using a VPN (I needed to install the VPN certificate to decrypt HTTPs traffic). The problem is I'm unable to connect to slack API

>>> import slackclient
>>> client = slackclient.SlackClient(myToken)
>>> client.server.rtm_connect()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/slackclient/server.py", line 131, in rtm_connect
    reply = self.api_requester.do(self.token, connect_method, timeout=timeout, post_data=kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/slackclient/slackrequest.py", line 104, in do
    proxies=self.proxies
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/adapters.py", line 511, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='slack.com', port=443): Max retries exceeded with url: /api/rtm.start (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)'),))

Versions are:

Python 2.7.15
certifi==2018.8.24
chardet==3.0.4
idna==2.7
jenkinsapi==0.3.6
pytz==2018.5
requests==2.19.1
setproctitle==1.1.10
six==1.11.0
slackclient==1.2.1
urllib3==1.23
websocket-client==0.51.0

Solution

  • I've found the problem. From some reason, python does not use the certificates in my key chain but the ones in the openssl under /Library/Frameworks/Python.framework/Versions/2.7/etc/openssl/cert.pem

    I've added the certificate at the bottom of file and the problem went away

    To find where the certificate is, start python and run the following:

    >>> import certifi
    >>> certifi.where()