TokenException: Token is invalid or has expired.

akshayt
I keep getting "TokenException: Token is invalid or has expired." error even after cross-checking the api_key and api_secretkey multiple times. Please help.

PS - Please find the error image below.


  • SRIJAN
    SRIJAN edited August 2022
    A request token is valid only for a couple of minutes, after that it expires.

    Make sure to use request token immediately after loggin in to your KiteConnect app .
  • akshayt
    I'm using it immediately after generating the token. All of it is running within the same code. So, I don't think there should be any delay
  • SRIJAN
    SRIJAN edited August 2022
    What do you mean by 'running within the same code'?

    Are you automating the login process??

    If so,then it's against the exchange regulations. Every user has to manually login atleast once a day.

    Try manual login and check.
  • akshayt
    Yes, I am trying to automate the login process.
    Tried manual login into the Kite portal and the Kite Connect portal as well but the result is still the same. The same error keeps popping up.
  • SRIJAN
    If you are sure that all your credentials/tokens are correct and you are still getting token exception,then request Sujith Sir or Rakesh Sir,only they can help you .
  • akshayt
    How exactly can they help? Do I need to provide my api keys to them and they can help identify the error from the backend? Can you please provide their contact?
  • SRIJAN
    SRIJAN edited August 2022
    Just tag or message them directly. @sujith Sir, @rakeshr Sir.
  • rakeshr
    TokenException: Token is invalid or has expired
    You need to recheck if you are passing the correct request token string. Recheck on reading values from the file part, if any extra values like `\n`, etc, get added while reading.
  • akshayt
    I had not authorized on the kite.trade website. That was the issue and hence my code was not able to move past that stage. Rectified error in the code and woosh, it started working.
This discussion has been closed.