ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connect

genesis
genesis edited November 2018 in Python client

from kiteconnect import KiteConnect

import logging
from kiteconnect import KiteTicker

logging.basicConfig(level=logging.DEBUG)

# Initialise
kws = KiteTicker(api_key, access_token)

def on_ticks(ws, ticks):
# Callback to receive ticks.
logging.debug("Ticks: {}".format(ticks))

def on_connect(ws, response):
# Callback on successful connect.
# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
ws.subscribe([53895943,256265])

# Set RELIANCE to tick in `full` mode.
ws.set_mode(ws.MODE_QUOTE, [53895943,256265])

def on_close(ws, code, reason):
# On connection close stop the main loop
# Reconnection will not happen after executing `ws.stop()`
ws.stop()

# kws.on_close = on_close

# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
# kws.on_close = on_close

kws.connect()

I am getting this error :

<del class="Delete"><del class="Delete"></del></del>ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))

api_key , access_token, public_token has been provided for.

api_key is working properly. I checked it using this :

Code :

import logging
from kiteconnect import KiteTicker , KiteConnect

logging.basicConfig(level=logging.DEBUG)

# Initialise
kite = KiteConnect(api_key = api_key)

for instruments in kite.instruments('NFO'):
print(instruments)
break

  • zartimus
    `kws = KiteTicker(api_key, access_token)`
    Are you sure you used access_token? Maybe you used public token.

    This code works perfectly alright.
Sign In or Register to comment.