First of all, thanks for all your support & coordination. I am using python client ticker, I have been observing "ERROR:kiteconnect.ticker: Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))" by every 2 or 3 days.
For example, I have generated new "access_token" on day 1 & KiteTicker is working fine with the ticker for 2 or 3 days and sometime in-between observed above error, and force to generate new "access_token".
I am sure, I am closing the connection using the right method. Need your guidance/help, please explain what is the process. Let me know if any more details required.
Following is Code Executed on Linux OS-
#!/usr/bin/env python3 import logging from kiteconnect import KiteTicker
def on_connect(ws, response): # Callback on successful connect. # Subscribe to a list of instrument_tokens (RELIANCE and ACC here). try: print("Starting The Connection") ws.subscribe() print("Connected Sucessfully")
# Set RELIANCE to tick in `full` mode. #ws.set_mode(ws.MODE_FULL, ) except Exception: print(Exception)
def on_close(ws, code, reason): # On connection close stop the main loop # Reconnection will not happen after executing `ws.stop()` print("Closing 'on_close' Connection") ws.stop()
def close(self, code=None, reason=None): print("'Close' the WebSocket connection.") if self.ws: self.ws.sendClose(code, reason)
# Assign the callbacks. kws.on_ticks = on_ticks kws.on_connect = on_connect kws.close = close kws.on_close = on_close
# Infinite loop on the main thread. Nothing after this will run. # You have to use the pre-defined callbacks to manage subscriptions. kws.connect()