kite.generate_session throwing invalid or token expired error

Amol_Kadam
Amol_Kadam edited September 2019 in Python client
Hi Team,
I am using two accounts and have two different apps created for trading using my software hosted on https://happytrades.net I have used the same URL as postback for both of my apps. Now I am able to do kite login using one account and when I do kite login using another account then I get the request token in the postback but however, I am getting an error as follows: The token is invalid or has expired., referer: https://kite.zerodha.com/connect/login?api_key=vhr8emfssapj175yx7j&sess_id=54BdAjagP5UBuDzALFQ2CX4wmvlbfLgO This error is on the line when I am generating the session using the line: kite = KiteConnect(api_key=self.api_key) kite.generate_session(request_token=request_token, api_secret=str(session['secret_key'])) This line is working fine for my one account.
When I try to login with a different account on another browser, then I am receiving the mentioned error.

kite = KiteConnect(api_key=api_key)#"rgeqni8asdfop6znpa7q")
data = kite.generate_session(request_token=request_token,api_secret=secret_key)

I tried generating secret key again for the account but again the same error is throwing.

Account number facing issue:ZP1323
Account number working fine: ZU7797

Could you please help me on this as this is back-end issue from KITE since for one account it is working fine and for another it is throwing an error.

Could you please suggest what supposed to be done in this case.Please let me know in case any further information is required.

Thanks in advance.
  • sujith
    You can try this.
  • Amol_Kadam
    @sujith: I don't want to identify the user since i am getting the request token but somehow it is throwing an invalid token error. I am getting the request token for first account successfully but for this user only it is throwing an error despite of passing the correct api_key and secret_key.
    I have confirmed the key values are getting passed correctly by using the debug mode.
    Issue is exactly similar like in below thread
    https://kite.trade/forum/discussion/3715/token-is-invalid-or-has-expired
    Could you please help in that direction.
  • sujith
    Are you using the corresponing api_key and secret while generating the session?
  • Amol_Kadam
    @sujith Yes . We are using the corresponding api key and secret only given in the app. Could you please confirm if there is any issue from backend or issue is with same redirect url is being used in both the apps.
  • sujith
    I just tried and it seems fine. Are you doing this manually or automating?
  • Amol_Kadam
    @sujith I am doing it manually and issue is resolved now.. It was happening due to space got appended in the api key. Now I am able to get the access token.
    Thanks a lot for all your help.
This discussion has been closed.