【发布时间】:2019-05-02 06:32:54
【问题描述】:
我有一个使用 http 运行良好的简单代码(不安全),但后来我将其更新为 https 得到一个关于 ssl.SSLCertVerificationError 的错误
当然,我正在使用具有有效 ssl 的 heroku 服务器,mac 上的 python 3.7.3,ssl.OPENSSL_VERSION= 1.1.0,certifi=2019.3.9,Flask=1.0.2,@ 987654325@=3.3.2
代码如下:
import socketio
sio = socketio.Client()
@sio.on('connect')
def on_connect():
print('Connected ...')
@sio.on('message')
def on_message(data):
print('I received a message!')
print(data)
if __name__ == '__main__':
sio.connect('https://heroku.server.url')
这就是我使用 https 得到的:
Traceback (most recent call last):
File "/Users/calavraian/Devel/Projects/FlaskTesting/Client.py", line 21, in <module>
sio.connect('https://heroku.server.url')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/socketio/client.py", line 208, in connect
engineio_path=socketio_path)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/engineio/client.py", line 166, in connect
url, headers, engineio_path)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/engineio/client.py", line 303, in _connect_polling
if self._connect_websocket(url, headers, engineio_path):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/engineio/client.py", line 341, in _connect_websocket
cookie=cookies)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_core.py", line 514, in create_connection
websock.connect(url, **options)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_core.py", line 223, in connect
options.pop('socket', None))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_http.py", line 126, in connect
sock = _ssl_socket(sock, options.sslopt, hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_http.py", line 260, in _ssl_socket
sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_http.py", line 239, in _wrap_sni_socket
server_hostname=hostname,
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)
有什么想法吗?
【问题讨论】:
-
你能分享错误的完整堆栈跟踪吗?
-
当然,我刚刚用完整的堆栈跟踪更新了帖子,谢谢!
-
1.如果您认为不应该提供 url,请删除跟踪栏 url(您似乎注意到了)。 2. 我刚刚测试了你的代码,它在 Linux 中使用 python-socketio-4.0.1 正常工作
-
感谢@eyllanesc 的建议,在这种情况下,服务器 url 不是问题,因为服务器只是为了测试它,我刚刚更新到
python-socketio-4.0.1,但我得到了同样的错误mac 与 macOS Mojave (10.14.4) ...我将尝试在 Linux 上进行测试。另一方面,我尝试使用 curl 命令从终端(从同一台机器)访问相同的 URL,并且 ssl 证书的验证效果很好。 -
我无法重现这个问题我可以很好地连接到 Heroku 应用程序。
标签: python python-3.x ssl websocket python-socketio