1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Flask-SocketIOで`No 'Access-Control-Arrow-Origin'`になる

Last updated at Posted at 2019-09-20

Flask + Flask-SocketIOの構成で、
socket-ioの通信が No 'Access-Control-Arrow-Origin' となった。

「Flask CORS」とかでググって出てくるFlask-CORSを使った方法では解決できずハマった。

環境

  • Python 3.7.4
  • Flask 1.1.1
  • Flask-SocketIO 4.2.1

解決

最終的に下記のコードで解決した。

from flask import Flask, render_template, request, redirect, url_for, session, make_response
from flask_socketio import SocketIO, emit, join_room, leave_room, close_room, rooms, disconnect

app = Flask(__name__)
socketio = SocketIO(app, cors_allowed_origins="*")

...

socketio.run(app, host="0.0.0.0", port=8000)

SocketIOサーバーオブジェクトを立ち上げる時の引数で cors_allowed_origins を指定できる

##参考
https://stackoverflow.com/questions/50632723/flask-socketio-failed-to-set-access-control-allow-origin-response-header

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?