I’ve been trying to send data from flask over socket io. I need to access this data from a different origin, but it is giving a CORS error. I have tried using all kinds of cross origin stuff and none of it has worked. Can somebody help with this.
The view that should be called thought socket io:
JavaScript
x
7
1
from flask.ext.cors import cross_origin
2
@socketio.on('increment',namespace="/api")
3
@cross_origin()
4
def increment(message):
5
number += 1;
6
emit('number',{'data':number},broadcast=True)
7
Running the server:
JavaScript
1
8
1
app = Flask(__name__)
2
cors = CORS(app,resources={r"/api/*":{"origins":"*"}})
3
socketio = SocketIO(app)
4
app.debug = True
5
app.host = '0.0.0.0'
6
7
socketio.run(app)
8
Advertisement
Answer
I solved by following:
JavaScript
1
2
1
socketio = SocketIO(app, cors_allowed_origins="*")
2