1006 connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))

itmmec
I am getting this error and was never able to use Zerosha web socket. Can anyone share the working code
import logging, time
from kiteconnect import KiteTicker

logging.basicConfig(level=logging.INFO)

API_KEY = "XXXXXXXXX"
ACCESS_TOKEN = "XXXXXXXXXXXX"

kws = KiteTicker(API_KEY, ACCESS_TOKEN)

def on_connect(ws, resp):
print("CONNECTED ✅")
ws.subscribe([738561])
ws.set_mode(ws.MODE_LTP, [738561])

def on_ticks(ws, ticks):
print("TICK:", ticks[0])

def on_error(ws, code, reason):
print("ERROR ❌:", code, reason)

def on_close(ws, code, reason):
print("CLOSED:", code, reason)

kws.on_connect = on_connect
kws.on_ticks = on_ticks
kws.on_error = on_error
kws.on_close = on_close

kws.connect(threaded=True)

# keep the cell alive for 20 seconds
time.sleep(20)
kws.close()
print("Stopped")
  • nagavenij
    A valid access token is required to connect to Kite Ticker. It appears that either the API key or the access token being passed is invalid. Kindly generate a new access token as mentioned in the documentation. You may refer to this forum discussion.
Sign In or Register to comment.