TokenException: Token is invalid or has expired.

sanjaya
sanjaya edited April 29 in General
Team:

I am getting below exception while creating access token, I have checked kite connect, my app is active and I am passing the right api_key and api_secret, request help

TokenException: Token is invalid or has expired.

I am using the code

# -*- coding: utf-8 -*-
"""
Connecting to KiteConnect API

@author: Sanjay
"""

from kiteconnect import KiteConnect
import pandas as pd

api_key = "actual api key"
api_secret = "actual api secret"
kite = KiteConnect(api_key=api_key)
print(kite.login_url()) #use this url to manually login and authorize yourself

#generate trading session
request_token = "Your Request Token" #Extract request token from the redirect url obtained after you authorize yourself by loggin in
data = kite.generate_session(request_token, api_secret=api_secret)

#create kite trading object
kite.set_access_token(data["access_token"])


#get dump of all NSE instruments
instrument_dump = kite.instruments("NSE")
instrument_df = pd.DataFrame(instrument_dump)
instrument_df.to_csv("NSE_Instruments.csv",index=False)
This discussion has been closed.