'Dash python-socketio notification emitting

I want to send push notification using socket.io to browser from my py dash UI by clicking button event.

I have dash app running locally on port 5301 (http://localhost:5301/) with basic auth i.e. user='skuser' and password : 'pwd@skuser'.

Inside my dash program I have following code added in one callback

import socketio
.....
....
@app.callback(Output('send-notification-output', 'children'),
          [Input('send-button', 'submit_n_clicks')
          ])
def  send_notification(n_click):
   sio = socketio.Client(engineio_logger=True)
   print("sio client created")
   sio.connect('http://skuser:pwd@skuser@localhost:5301/')
   print("connected")
   sio.emit('notification_msg', 'hello world')

Now when send-button is clicked i.e. this callback is triggered in dash, I am getting following error:

*Traceback (most recent call last): File "C:\Users\XXXXX\Anaconda3\lib\site-packages\socketio\client.py", line 333, in connect engineio_path=socketio_path)

File "C:\Users\XXXXX\Anaconda3\lib\site-packages\engineio\client.py", line 186, in connect url, headers or {}, engineio_path)

File "C:\Users\XXXXX\Anaconda3\lib\site-packages\engineio\client.py", line 296, in _connect_polling r.status_code), arg)

engineio.exceptions.ConnectionError: ('Unexpected status code 403 in server response', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\XXXXX\Anaconda3\lib\site-packages\socketio\client.py", line 338, in connect raise exceptions.ConnectionError(exc.args[0]) from None socketio.exceptions.ConnectionError: Unexpected status code 403 in server response*

Please help me what is wrong in this implementation.

Getting following info as well:

Attempting polling connection to http://skuser:pwd@skuser@localhost:5301/socket.io/?transport=polling&EIO=4

Why socket.io/?transport=polling&EIO=4 is added in the baseurl?

Please help!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source