Help us understand the problem. What is going on with this article?

Flask-SocketIOで

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

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away