应用引擎、Flask-Socketio服务器Cors_Allowed_Origins标头丢失
当我尝试从客户端向部署在应用引擎上的 socketio Flask 服务器发送请求时,我收到以下错误:
已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。
我确实在我的 python 服务器脚本中添加了以下行:
socketio = SocketIO(app, cors_allowed_origins='*')
我还添加了以下行:
CORS(app)
我究竟做错了什么?
我尝试使用 url 处理程序的 Allow_cors_origin 更改 app.yaml,安装flask-cors 包,但没有任何效果
编辑:我在调试时在应用引擎中发现以下消息:
{
"textPayload": "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)",
"insertId": "5fca5af900064b8faf6f9267",
"resource": {
"type": "gae_app",
"labels": {
"module_id": "default",
"project_id": "island-battles",
"version_id": "20201204t174848",
"zone": "europe-west6-3"
}
},
"timestamp": "2020-12-04T15:51:21.412559Z",
"labels": {
"clone_id": "00c61b117cf0689fb08fabba9037f4624c77b480da8e9472be2b02038e0fe7d2d8dcac81021c"
},
"logName": "projects/island-battles/logs/stderr",
"receiveTimestamp": "2020-12-04T15:51:21.465294012Z"
}
How do I fix this? Thanks
SECOND EDIT:
Everything works fine in my local version, the problem lies with app engine
回答
如果您使用 Flask-SocketIO,请确保安装兼容版本,最新版本与 python-socketio 3.1.2 不兼容,您将收到错误消息。
我跑了:
pip install python-socketio==3.1.2
正如 Oliver 所建议的,但由于我的 Flask-SocketIO 版本为 5.0.1 出现错误,所以我运行了以下命令:
pip install flask-socketio==4.3.2
这解决了我的问题。
最终你会想要 flask-socketio-4.3.2 python-engineio-3.14.2 python-socketio-4.6.1
这里得出了类似的结论:https
:
//github.com/miguelgrinberg/Flask-SocketIO/issues/1432 https://github.com/juharris/switch-remoteplay/issues/37