过去几天,当我尝试运行示例 python websocket Flexible-app-engine 应用程序时出现以下错误(https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/flexible/websockets)。它以前可以工作,但现在当我运行时,我看到以下错误。
当我使用“gunicorn -b 127.0.0.1:8080 -k flask_sockets.worker main:app”在本地运行时,我没有看到这个问题。
仅当我在谷歌云中部署时才会看到此问题。
File "/env/lib/python3.6/site-packages/gevent/pywsgi.py", line 999, in handle_one_response
self.run_application()
File "/env/lib/python3.6/site-packages/geventwebsocket/handler.py", line 75, in run_application
self.run_websocket()
File "/env/lib/python3.6/site-packages/geventwebsocket/handler.py", line 52, in run_websocket
list(self.application(self.environ, lambda s, h, e=None: []))
File "/env/lib/python3.6/site-packages/flask/app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "/env/lib/python3.6/site-packages/flask_sockets.py", line 40, in __call__
handler, values = adapter.match()
File "/env/lib/python3.6/site-packages/werkzeug/routing.py", line 2026, in match
raise WebsocketMismatch()
werkzeug.routing.WebsocketMismatch: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
{
textPayload: "2021-05-14T22:33:23Z {'REMOTE_ADDR': '172.17.0.4', 'REMOTE_PORT': '23300', 'HTTP_HOST': 'malware-sandboxing.uc.r.appspot.com', (hidden keys: 39)} failed with WebsocketMismatch
"
insertId: "nn71n3jmo5u1ymw9s"
resource: {2}
timestamp: "2021-05-14T22:33:23Z"
labels: {4}
logName: "projects/malware-sandboxing/logs/appengine.googleapis.com%2Fstderr"
receiveTimestamp: "2021-05-14T22:33:26.911503907Z"
}
请帮忙
答案1
我最近在 App Engine Flex 上也遇到了同样的问题。通过更新如下requirements.txt
所述,此问题已得到解决。我使用的是不同版本的Flask
和gunicorn
Flask==1.1.4
Flask-Sockets==0.2.1
gunicorn==20.1.0
requests==2.25.1
你可以尝试一下。