python flask_socketio 连接异常报错

使用flask_socketio搭建一个ws程序,运行后服务端报错

The client is using an unsupported version of the Socket.IO or Engine.IO protocols (further occurrences of this error will be logged with level INFO)

以下是代码

服务端:

from flask import Flask, render_template
from flask_socketio import SocketIO,emit
from threading import Lock
import random
async_mode = None
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
thread = None
thread_lock = Lock()

@app.route('/')
def index():
    return render_template('app.html')

@socketio.on('connect', namespace='/test_conn')
def test_connect():
    global thread
    with thread_lock:
        if thread is None:
            thread = socketio.start_background_task(target=background_thread)

def background_thread():
    while True:
        socketio.sleep(5)
        t = random.randint(1, 100)
        socketio.emit('server_response',
                      {'data': t},namespace='/test_conn')

if __name__ == '__main__':
    socketio.run(app, debug=True)

客户端:

html>
<html>

<head>
  <meta charset="UTF-8">
  <title>title>
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.4.2.min.js">script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js">script>
head>

<body>
  <h1 id="t">h1>
  <script type="text/javascript">
    $(document).ready(function () {
      namespace = '/test_conn';
      var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port + namespace, { transports: ['websocket'] });
      socket.on('server_response', function (res) {
        console.log(res.data);
        $('#t').text(res.data);
      });
    });
  script>
body>

html>

如果是版本问题,请问应该下载那个版本呢?

客户端的使用了 Socket.IO 或 Engine.IO protocols 不支持的版本,建议升级版本即可。下载最新或次新的版本即可,新版本都是向下兼容的,所以下新的版本一般都没有错。 望采纳,望采纳,祝你的问题早日解决!!!