Invalid Token


I was trying to get the historical data for a single instrument token using kiteconnect. The code for the same is as shown:

from kiteconnect import KiteConnect
from kiteconnect import KiteTicker
import os
import datetime as dt
import pandas as pd

api_k = ""
api_s = ""

def get_login(api_k, api_s):
global kws, kite
kite = KiteConnect(api_key=api_k)
print("[*] Generate access Token : ", kite.login_url())
request_tkn = input("[*] Enter Your Request Token Here : ")

data = kite.generate_session(request_tkn, api_secret=api_s)

kws = KiteTicker(api_k, data["access_token"])

# Example usage:
get_login(api_k, api_s)

vfrom = "2023-08-05"
vto = "2023-12-10"

ohlc = kite.historical_data(12053506, vfrom, vto, '30minute')


When I run this code I get the following error: 'invalid token'

I must mention that the API token is freshly generated today and the other kiteconnect calls such as those for fetching ohlc data work perfectly.

May I know why is my call not working?
  • sujith
    You shouldn't call generate session every time you run the script. You can know more about it here.
Sign In or Register to comment.