Flask-SocketIO AttributeError:“服务器”对象没有属性“get_environ”

问题描述 投票:0回答:1

我似乎无法弄清楚这一点。我正在使用旧版本的 Flask/socketio 库,以便让它们正常工作,而不会出现与我的 socket.io-client 的连接问题。

当我尝试连接到套接字时出现错误消息:

301cd1879aca4952ab7c172036986e72: Sending packet OPEN data {'sid': '301cd1879aca4952ab7c172036986e72', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}  connect handler error Traceback (most recent call last): File "C:\Users\Ryan\Desktop\affederation-website\backend\venv\Lib\site-packages\engineio\server.py", line 549, in _trigger_event return self.handlers[event](*args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Ryan\Desktop\affederation-website\backend\venv\Lib\site-packages\socketio\server.py", line 724, in _handle_eio_connect return self._handle_connect(sid, '/') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Ryan\Desktop\affederation-website\backend\venv\Lib\site-packages\socketio\server.py", line 627, in _handle_connect success = self._trigger_event('connect', namespace, sid, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Ryan\Desktop\affederation-website\backend\venv\Lib\site-packages\socketio\server.py", line 711, in _trigger_event return self.handlers[namespace][event](*args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Ryan\Desktop\affederation-website\backend\venv\Lib\site-packages\flask_socketio\__init__.py", line 282, in _handler return self._handle_event(handler, message, namespace, sid, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Ryan\Desktop\affederation-website\backend\venv\Lib\site-packages\flask_socketio\__init__.py", line 790, in _handle_event environ = self.server.get_environ(sid, namespace=namespace) ^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Server' object has no attribute 'get_environ'

服务器.py

app = Flask(__name__, static_folder="../dist", static_url_path="")
CORS(app, resources={r"/*": {"origins": "*"}})
socketio = SocketIO(app, logger=True, engineio_logger=True, cors_allowed_origins="*")
        
@socketio.on("connect")
def handle_connect():
    print("Connected")
 #   emit("connect")

@socketio.on("disconnect")
def handle_disconnect():
    print("Client has disconnected")
  #  emit("disconnect")

点冻结:

Flask==2.3.2
Flask-Cors==4.0.0
Flask-SocketIO==5.3.4
python-engineio==3.13.2
python-socketio==4.6.0
flask websocket flask-socketio
1个回答
0
投票

您正在使用一个相当新的 Flask-SocketIO(从 2023 年开始)库,以及旧的 python-socketio 和 python-engineio 依赖项(从 2020 年开始)。将两个依赖项升级到当前版本,或者将 Flask-SocketIO 降级到与您的依赖项大致相同的日期。

© www.soinside.com 2019 - 2024. All rights reserved.