1006 - connection was closed uncleanly (WebSocket closing handshake timeout

Vishnuvardhan
Dear Team,

I am facing this error only on some days and other days I don't face error with same code.
Connection error: 1006 - connection was closed uncleanly (WebSocket closing handshake timeout (peer did not finish the opening handshake in time))

Below is the code, can you please help me to fix this error which is causing intermittently ?


def on_ticks(ws, ticks):
ltp_store.update({str(tick['instrument_token']): tick['last_price'] for tick in ticks})
# ws.unsubscribe(ticks)


def on_connect(ws, response):
# Callback on successful connect.
ws.subscribe(list_result)
ws.set_mode(ws.MODE_LTP, list_result)

def on_close(ws, code, reason):
logging.info("Connection Closed ==== WS")

def connect_to_kite_ticker():
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
try:
kws.connect(threaded=True)
except Exception as e:
logging.error(f"Error occurred at Socket Connection : {e}")
tm.sleep(10) # Allow some time for receiving ticks
kws.close() # Close web socket connection once ticks receives
Sign In or Register to comment.