Frequently token gets invalidated

m1ahess
m1ahess edited December 2021 in Python client
creds = kite_initialize.getCreds()
kite = KiteConnect(api_key=creds['api_key'])
data = kite.generate_session(creds['access_token'], api_secret=creds['api_secret'])
kite.set_access_token(data["access_token"])
However the this token I generated using the exact steps followed as in https://github.com/zerodha/pykiteconnect#api-usage expires in few minutes

After using the this token for a min, the token is expired and next time when I make any kite api call with this session, it says tokenException
  • Imran
    Imran edited December 2021
    Hello @m1ahess
    When you will be logging in to kite for the first time, you need to pass the request token in kite.generate_session() . Once session is generated and you get access token in data,save access token into a text file.
    If the session fails, so while logging in to Kite next time, you don't need to call kite.generate_session() only give call to kite.set_access_token(access_token). Here access_token will be called from where you have stored it when its generated initially.
  • m1ahess
    @Imran Didnt get you? which one I should use through the day ?access_token obtained from genrate_session ? or the request token obtained from the redirect url ?
    I thought the later and every few mins it gets disconnected!
  • Imran
    @m1ahess
    Request token obtained from the redirect URL expires in a couple of minutes
    You have to use access_token obtained from generate_session() throughout the day.
Sign In or Register to comment.