Search code examples
pythongoogle-app-engineflasksocket.ioflask-socketio

App engine, Flask-Socketio server Cors_Allowed_Origins header is missing


When I try to send a request from the client to my socketio flask server that is deployed on app engine I recieve the following error:

has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I did put the following line in my python server script:

socketio = SocketIO(app, cors_allowed_origins='*')

I also added the folling line:

CORS(app)

What am I doing wrong?

I tried changing the app.yaml with the Allow_cors_origin of the url handler, installing flask-cors package, nothing worked

EDIT: I found in the app engine the following message while debugging:

{ "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


Solution

  • This error is due to an unsupported Socket IO version. I imagine you are using the latest version, however, App Engine usually takes some time to support the latest versions. Try downgrading it to v3.x, maybe even v2.x.

    You can install specific versions of packages with $ pip install <PACKAGE>==<VERSION>, in this case, for example: $ pip install python-socketio==3.1.2.