Itai Elidan
Itai Elidan

Reputation: 272

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

Upvotes: 4

Views: 10277

Answers (3)

unknowCoder.py
unknowCoder.py

Reputation: 1

Bycors_allowed_origins option

For examplehttp://127.0.0.1:8283,server.py script

sio = socketio.Server(cors_allowed_origins='http://127.0.0.1:8283')

Upvotes: 0

Emily
Emily

Reputation: 101

If you're using Flask-SocketIO make sure to install a compatible version, the latest is not compatible with python-socketio 3.1.2 and you will get an error.

I ran:

pip install python-socketio==3.1.2 

as suggested by Oliver but had error because I had Flask-SocketIO version 5.0.1, so I ran the following:

pip install flask-socketio==4.3.2

and that solved my issues.

Ultimately you'd want flask-socketio-4.3.2 python-engineio-3.14.2 python-socketio-4.6.1

Similar conclusion reached here: https://github.com/miguelgrinberg/Flask-SocketIO/issues/1432 https://github.com/juharris/switch-remoteplay/issues/37

Upvotes: 5

Oliver Aragon
Oliver Aragon

Reputation: 488

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.

Upvotes: 3

Related Questions