我的设置是Mac OS 10.13.6(更新),python 2.7.15,并且使用VPN连接(我需要安装VPN证书才能解密HTTPs流量)。 问题是我无法连接到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)'),))
版本为:
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
答案 0 :(得分:2)
我发现了问题。 由于某种原因,python不使用我的密钥链中的证书,而是使用/library/Frameworks/Python.framework/Versions/2.7/etc/openssl/cert.pem
下的openssl中的证书。我已经在文件底部添加了证书,问题就消失了
答案 1 :(得分:0)
另一种解决方案,当slackclient调用websocket-client时添加No cert选项 在文件“ c:/Python27/Lib/site-packages/slackclient/server.py”中
添加第180行,sslopt = {'cert_reqs':0}
line 176: self.websocket = create_connection(ws_url,
line 177: http_proxy_host=proxy_host,
line 178: http_proxy_port=proxy_port,
line 179: http_proxy_auth=proxy_auth,
line 180: sslopt={'cert_reqs':0})
答案 2 :(得分:0)
另一种解决方案, 在您的钥匙串访问权限中,删除slack.com令牌