I am getting this error while connecting to my Flask app using socket.io
GET http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1450525025659-286 Request.create @ socket.io.js:2919Request @ socket.io.js:2842XHR.request @ socket.io.js:2773XHR.doPoll @ socket.io.js:2803Polling.poll @ socket.io.js:3192Polling.doOpen @ socket.io.js:3136Transport.open @ socket.io.js:2313Socket.open @ socket.io.js:1743Socket @ socket.io.js:1625Socket @ socket.io.js:1560Manager.open.Manager.connect @ socket.io.js:299(anonymous function) @ socket.io.js:564 :3004/:1 XMLHttpRequest cannot load http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1450525025659-286. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3004' is therefore not allowed access. The response had HTTP status code 500.
I tried this solution
@app.after_request
def add_cors(resp):
resp.headers['Access-Control-Allow-Origin'] = request.headers.get('Origin','*')
resp.headers['Access-Control-Allow-Credentials'] = 'true'
resp.headers['Access-Control-Allow-Methods'] = 'POST, OPTIONS, GET'
resp.headers['Access-Control-Allow-Headers'] = request.headers.get(
'Access-Control-Request-Headers', 'Authorization')
return resp
But it did not work. I also tried Flask-Cors module
CORS(app, resources={
r'/*/*': {
'origins': '*',
'allow_headers': ['Content-Type', 'Authorization']
}
})
and no gain. Any help would be appreciated