以下是我的完整应用程序代码
from flask import Flask, render_template, request, session, redirect, url_for
from flask_socketio import SocketIO, join_room, send
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secretjsidfjsidfjsdifjsdifj!'
socketio = SocketIO(app)
@app.route('/')
def index():
return render_template('index.html')
@socketio.on('message')
def handle_message(msg):
print('get message:'+ msg)
send(msg, broadcast=True)
if __name__ == "__main__":
socketio.run(app)
当我运行socketio服务器时,它会显示
skysea@qiuyuxuandeAir flask-test % python3 app.py
WebSocket transport not available. Install simple-websocket for improved performance.
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
http://localhost:5000 is not an accepted origin. (further occurrences of this error will be logged with level INFO)
127.0.0.1 - - [28/May/2021 12:42:45] "GET /socket.io/?EIO=4&transport=polling&t=NcnI2J7 HTTP/1.1" 400 -
但是我已经安装了simple-websocket
这是我的Flask-socketIO信息
skysea@qiuyuxuandeAir flask-test % pip3 show flask_socketio
Name: Flask-SocketIO
Version: 5.0.3
Summary: Socket.IO integration for Flask applications
Home-page: http://github.com/miguelgrinberg/Flask-SocketIO/
Author: Miguel Grinberg
Author-email: miguelgrinberg50@gmail.com
License: MIT
Location: /opt/homebrew/lib/python3.9/site-packages
Requires: python-socketio, Flask
Required-by:
这是我的simple-websocket信息
skysea@qiuyuxuandeAir flask-test % pip3 show simple-websocket
Name: simple-websocket
Version: 0.2.0
Summary: Simple WebSocket server and client for Python
Home-page: https://github.com/miguelgrinberg/simple-websocket
Author: Miguel Grinberg
Author-email: miguel.grinberg@gmail.com
License: UNKNOWN
Location: /opt/homebrew/lib/python3.9/site-packages
Requires: wsproto
Required-by:
我使用的是 Mac M1,我该如何解决这个问题?