5

I have a simple Flask chat application that I am testing out coming from a tutorial. Supposedly I just need to run it using the "python app.py" command but when I access it via http://localhost:5000 i get a continuous message of this:

Console

I was hoping to get 200. I have Flask, Flask-SocketIO, and eventlet already installed. Any idea that can point me in the right direction? Thank you.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
siopaoman
  • 1,733
  • 2
  • 12
  • 7

2 Answers2

12

The current release of Flask-SocketIO has stricter requirements with regards to cross-origin requests. adding cors_allowed_origins='https://localhost will resolve the error.
i.e. SocketIO(app,cors_allowed_origins="http://localhost") or
SocketIO(app,cors_allowed_origins="*") hopefully this work.

Mamun
  • 456
  • 7
  • 9
  • 1
    yay! it worked. this is the correct answer. thank you so much. – siopaoman Aug 09 '19 at 08:38
  • 2
    hi, @Mamun, I still have the same issue. I added cors_allowed_origin but still I am getting continous messages as shown in the question:/ Can you help? –  May 24 '21 at 17:17
2

The code from the Flask-SocketIO documentation also produced the same error for me. However this example code did not (also in debug mode): https://github.com/miguelgrinberg/Flask-SocketIO

In both, the fix above is not included. Changing the HTML script tags helped.

From:

<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>

To:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.4/socket.io.js" integrity="sha512-aMGMvNYu8Ue4G+fHa359jcPb1u+ytAF+P2SCb+PxrjCdO3n3ZTxJ30zuH39rimUggmTwmh2u7wvQsDTHESnmfQ==" crossorigin="anonymous"></script>
jlee7
  • 126
  • 8