我有这个
Python
代码,我想使用 SSL
进行连接。
import socketio
from eventlet import listen, wrap_ssl
from eventlet.wsgi import server
from flask import Flask
from werkzeug.middleware.dispatcher import DispatcherMiddleware
app = Flask(__name__)
app1 = Flask(__name__)
sio = socketio.Server(async_mode="eventlet")
app.wsgi_app = socketio.WSGIApp(sio, DispatcherMiddleware(app, {"/app1": app1}))
server(listen(("localhost", 80)), app)
以下是我的
Python
和 Package
版本详细信息:
Python 3.10.7 64-bit
python-socketio==5.8.0
eventlet==0.33.3
Flask==2.3.1
Werkzeug==2.3.0
26.06 更新:
在谷歌上搜索并阅读
eventlet
的文档后。我有新版本的代码。
import socketio
from eventlet import listen
from eventlet.wsgi import server
from flask import Flask
from werkzeug.middleware.dispatcher import DispatcherMiddleware
app = Flask(__name__)
app1 = Flask(__name__)
sio = socketio.Server(async_mode="eventlet")
app.wsgi_app = socketio.WSGIApp(sio, DispatcherMiddleware(app, {"/app1": app1}))
server(wrap_ssl(listen(("127.0.0.1", 443)), certfile='MyCert.crt', keyfile='MyPrivate.key'), app)
但是现在我收到以下错误。
(17524) wsgi starting up on https://127.0.0.1:443
(17524) accepted ('127.0.0.1', 62260)
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\site-packages\eventlet\hubs\selects.py", line 59, in wait
listeners.get(fileno, hub.noop).cb(fileno)
File "C:\Program Files\Python310\lib\site-packages\eventlet\greenthread.py", line 221, in main
result = function(*args, **kwargs)
File "C:\Program Files\Python310\lib\site-packages\eventlet\wsgi.py", line 837, in process_request
proto.__init__(conn_state, self)
File "C:\Program Files\Python310\lib\site-packages\eventlet\wsgi.py", line 350, in __init__
self.handle()
File "C:\Program Files\Python310\lib\site-packages\eventlet\wsgi.py", line 383, in handle
self.handle_one_request()
File "C:\Program Files\Python310\lib\site-packages\eventlet\wsgi.py", line 412, in handle_one_request
self.raw_requestline = self._read_request_line()
File "C:\Program Files\Python310\lib\site-packages\eventlet\wsgi.py", line 395, in _read_request_line
return self.rfile.readline(self.server.url_length_limit)
File "C:\Program Files\Python310\lib\socket.py", line 705, in readinto
return self._sock.recv_into(b)
File "C:\Program Files\Python310\lib\site-packages\eventlet\green\ssl.py", line 253, in recv_into
return self._base_recv(nbytes, flags, into=True, buffer_=buffer)
File "C:\Program Files\Python310\lib\site-packages\eventlet\green\ssl.py", line 268, in _base_recv
read = self.read(nbytes, buffer_)
File "C:\Program Files\Python310\lib\site-packages\eventlet\green\ssl.py", line 187, in read
return self._call_trampolining(
File "C:\Program Files\Python310\lib\site-packages\eventlet\green\ssl.py", line 162, in _call_trampolining
return func(*a, **kw)
File "C:\Program Files\Python310\lib\ssl.py", line 1130, in read
return self._sslobj.read(len, buffer)
ssl.SSLError: [SSL: SSLV3_ALERT_CERTIFICATE_UNKNOWN] sslv3 alert certificate unknown (_ssl.c:2548)
Removing descriptor: 852
你解决了吗?我也有同样的问题