我可以在本地Windows上使用示例应用程序(https://github.com/miguelgrinberg/Flask-SocketIO/tree/master/example)statrt,但是在服务器centos失败错误400上,我使用gunicorn + nginx + eventlet。
日志:
2019-12-19 16:20:41,694 - INFO: 30bd9dce92f245698ae73dfec9fc0197: Sending packet MESSAGE data 0 - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/socket.py:95]
2019-12-19 16:20:41,730 - INFO: 30bd9dce92f245698ae73dfec9fc0197: Received packet MESSAGE data 0/test, - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/socket.py:52]
2019-12-19 16:20:41,731 - INFO: 30bd9dce92f245698ae73dfec9fc0197: Sending packet MESSAGE data 2/test,["my_response",{"data":"Connected","count":0}] - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/socket.py:95]
2019-12-19 16:20:41,731 - INFO: 30bd9dce92f245698ae73dfec9fc0197: Sending packet MESSAGE data 0/test - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/socket.py:95]
2019-12-19 16:20:41,732 - INFO: 30bd9dce92f245698ae73dfec9fc0197: Received request to upgrade to websocket - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/socket.py:105]
2019-12-19 16:21:12,524 - WARNING: Invalid session 30bd9dce92f245698ae73dfec9fc0197 - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/server.py:370]
2019-12-19 16:21:13,708 - INFO: 64aaa335d03e48adbca4d6db461ba372: Sending packet OPEN data {'sid': '64aaa335d03e48adbca4d6db461ba372', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000} - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/socket.py:95]
2019-12-19 16:21:13,709 - INFO: 64aaa335d03e48adbca4d6db461ba372: Sending packet MESSAGE data 0 - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/socket.py:95]
2019-12-19 16:21:13,744 - INFO: 64aaa335d03e48adbca4d6db461ba372: Received request to upgrade to websocket - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/socket.py:105]
2019-12-19 16:21:44,711 - WARNING: Invalid session 64aaa335d03e48adbca4d6db461ba372 - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/server.py:390]
2019-12-19 16:21:44,712 - WARNING: Invalid session 64aaa335d03e48adbca4d6db461ba372 - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/server.py:370]
2019-12-19 16:21:46,801 - INFO: da4cbf9a20ba4bfc9cd731644bd4bf6f: Sending packet OPEN data {'sid': 'da4cbf9a20ba4bfc9cd731644bd4bf6f', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000} - [in /home/venv/py37sio/lib/python3.7/site-packages/engineio/socket.py:95]
然后我不使用nginx + gunicorn,运行python3 app.py
没问题。
但是只要使用gunicorn gunicorn -w 1 -b 127.0.0.1:5000 app:app
,还有上面日志中的详细信息...
所以我想问题出在金枪鱼,但是我不知道如何解决〜。〜
答案 0 :(得分:0)
我需要使用eventlet worker类型启动Gunicorn:
gunicorn -w 1 -k eventlet -b 127.0.0.1:5000