【报错】flask-socketio failed: Error during WebSocket handshake: Unexpected response code: 500
今天遇到个很奇怪的问题,flask-socketio本地跑的时候,没有报错,但是一旦部署到线上,就报了 failed: Error during WebSocket handshake: Unexpected response code: 500
的错误。后来查看服务器日志:出现了以下错误:
RuntimeError: You need to use the gevent-websocket server. See the Deployment section of the documentation for more information.
原因:
最新的flask_socketio 使用的是python-socketio
如果在包中安装了gevent或evenlet,在服务器上使用时,就会报错
解决:
查看服务器安装的库,服务器上有,但是我本地没有,这就是问题所在了,卸载gevent和evenlet有关的库,然后重启服务就行了。
pip3 freeze
pip3 uninstall gevent-websocket
pip3 uninstall gevent