4

Im trying to create connection between flask socketio and react native socketio, I have already prepared client side with react native socketio BUT I have run into problem with importing flask_socketio in rpi. Im trying to use simplest implementation possible, this is my code:

from flask import Flask
from flask_socketio import SocketIO, emit
 
app = Flask(__name__)
 
@app.route('/', methods=['GET'])
def hello_world():
    return "Hello World"
 
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5005)

Without line 2 it works perfectly but I need to use flask_socketio. here is photo too(first run is without importing flask_socketio, than I tried to import it and it wont work. I have tried reinstalling flask_socketio twice, rebooting but nothing works:/enter image description here:

ersi
  • 207
  • 1
  • 2
  • 11

3 Answers3

4

Problem was that I was installing it with sudo python pip install flask_socketio, BUT I had to use python3, so right installation is python3 -m pip install flask_socketio

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
ersi
  • 207
  • 1
  • 2
  • 11
1

You need to go to cmd prompt and use:

sudo -H pip3 install flask-socketio
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Marcus
  • 11
  • 1
-1

This might resolve your problem

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

this will work on any version of socketio

jhoepken
  • 1,842
  • 3
  • 17
  • 24
Hedi Mzah
  • 21
  • 2