Issue
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:
from flask.ext.cors import cross_origin
@socketio.on('increment',namespace="/api")
@cross_origin()
def increment(message):
number += 1;
emit('number',{'data':number},broadcast=True)
Running the server:
app = Flask(__name__)
cors = CORS(app,resources={r"/api/*":{"origins":"*"}})
socketio = SocketIO(app)
app.debug = True
app.host = '0.0.0.0'
socketio.run(app)
Solution
I solved by following:
socketio = SocketIO(app, cors_allowed_origins="*")
Answered By - Zhang Buzz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.