monkeymademe / piritos

42 stars 6 forks source link

TypeError: emit() got an unexpected keyword argument 'broadcast' #4

Open Miniontoby opened 1 year ago

Miniontoby commented 1 year ago
Job "getsensordata (trigger: date[2023-04-15 10:58:16 CEST], next run at: 2023-04-15 10:58:16 CEST)" raised an exception
Traceback (most recent call last):
  File "/home/pi/flasks/flask_env/lib/python3.7/site-packages/apscheduler/executors/base.py", line 125, in run_job
    retval = job.func(*job.args, **job.kwargs)
  File "app.py", line 364, in getsensordata
    socketio.emit('updateSensorData', sensordata, broadcast=True)
  File "/home/pi/flasks/flask_env/lib/python3.7/site-packages/flask_socketio/__init__.py", line 463, in emit
    skip_sid=skip_sid, callback=callback, **kwargs)
TypeError: emit() got an unexpected keyword argument 'broadcast'

This is with flask_socketio version 5.3.2 and the solution is to remove the broadcast=True argument from all socketio.emit function calls (NOT FROM emit() inside the @socketio.on('message') functions!)

This is because socketio.emit is already sending to ALL connected users by default (unless you set the to argument)

This is the only solution according to the devs of flask_socketio as can be seen at https://github.com/miguelgrinberg/Flask-SocketIO/discussions/1972