Getting error while connecting websocket

ksmaheshkumar
Hi,


I am getting "ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))" error while trying to get the ticks.

My code is

from kiteconnect import KiteTicker
import logging

logging.basicConfig(level=logging.DEBUG)
api_key="api"
access_token="token"
tokens=[14668802]
kws=KiteTicker(api_key,access_token)
def on_ticks(ws,ticks):
for tick in ticks:
print('last_price',tick['last_price'],'date',tick['timestamp'])


def on_connect(ws,response):
ws.subscribe(tokens)
ws.set_mode(ws.MODE_FULL,tokens)

kws.on_ticks=on_ticks
kws.on_connect=on_connect
kws.connect()


I tried multiple times with different access token, still same error.

Would be great if anyone of you share the working code or correct the mistake in the code.

Thanks
Mahesh
  • ksmaheshkumar
    @sujith The Example mentioned on https://kite.trade/docs/pykiteconnect/v3/ticker.m.html is also not working,
    Can you please share the working example.
  • sujith
    Are you sure you are sending a valid access token?
  • ksmaheshkumar
    Yes i am sure. if you want i can share you my api and access token (Newly generated)
  • ksmaheshkumar
    After adding this code its working

    api_key="api"
    access_token="token"
    tokens=[14668802]
    kite = KiteConnect(api_key=api_key)
    data = kite.generate_session(access_token, api_secret=api_secret)
    kws=KiteTicker(api_key,data["access_token"])


    I used request token as access token thats what caused the confusion.
    Thanks for the response
This discussion has been closed.