通过python-socketio发送数据但无法在flask socketio上接收数据

我正在尝试从使用 python-socketio 的客户端发送数据,如下所述

#Client.py
import time
import socketio
sio = socketio.Client(engineio_logger=True)
start_timer = None

# if __name__ == '__main__':
sio.connect('http://127.0.0.1:3000')
sio.wait()
sio.emit('connect', {"Data": "Device_id"})

并尝试在使用flask-socketio的服务器上,如下面的代码中所述

#Server.py
from flask import Flask, render_template, request, jsonify
from flask_socketio import SocketIO
app = Flask(__name__)
# app.config['SECRET_KEY'] = "Social Distance Secret"
socket_app = SocketIO(app)

@socket_app.on('connect')
def handle_id(data):
    print(data)
    print(request.sid)

if __name__ == '__main__':
    socket_app.run(app, debug=True, host='127.0.0.1', port=3000)

我能够接收 sid,但在发送到 WebSocket 时无法获取我在 client.py 中给出的参数

# Error Server.py
Traceback (most recent call last):
  File "C:Usersvarul.jainAppDataLocalProgramsPythonPython36libsite-packagesengineioserver.py", line 545, in _trigger_event
    return self.handlers[event](*args)
  File "C:Usersvarul.jainAppDataLocalProgramsPythonPython36libsite-packagessocketioserver.py", line 721, in _handle_eio_connect
    return self._handle_connect(sid, '/')
  File "C:Usersvarul.jainAppDataLocalProgramsPythonPython36libsite-packagessocketioserver.py", line 626, in _handle_connect
    self.environ[sid])
  File "C:Usersvarul.jainAppDataLocalProgramsPythonPython36libsite-packagessocketioserver.py", line 708, in _trigger_event
    return self.handlers[namespace][event](*args)
  File "C:Usersvarul.jainAppDataLocalProgramsPythonPython36libsite-packagesflask_socketio-4.3.1.dev0-py3.6.eggflask_socketio__init__.py", line 283, in _handler
    *args)
  File "C:Usersvarul.jainAppDataLocalProgramsPythonPython36libsite-packagesflask_socketio-4.3.1.dev0-py3.6.eggflask_socketio__init__.py", line 711, in _handle_event
    ret = handler()
TypeError: handle_id() missing 1 required positional argument: 'data'

# Errors client.py:
Attempting polling connection to http://127.0.0.1:3000/socket.io/?transport=polling&EIO=3
Traceback (most recent call last):
  File "C:/Users/varul.jain/Desktop/people_counter/listenn.py", line 12, in <module>
    sio.connect('http://127.0.0.1:3000')
  File "C:Usersvarul.jainAppDataLocalProgramsPythonPython36libsite-packagessocketioclient.py", line 279, in connect
    six.raise_from(exceptions.ConnectionError(exc.args[0]), None)
  File "<string>", line 3, in raise_from
socketio.exceptions.ConnectionError: Unexpected status code 401 in server response

任何建议都会很有帮助

stack overflow Sending data through python-socketio but unable to receive data on flask socketio
原文答案