Unable to get access token

VKJ722
Now I am able to get the 'request token' in the redirect URL. I used that in the following python script: -
from kiteconnect import KiteConnect

API_KEY = "my api key"
API_SECRET = "my api secret"

kite = KiteConnect(api_key=API_KEY)

print("LOGIN URL:")
print(kite.login_url())

request_token = input("Paste request_token: ").strip()

session = kite.generate_session(request_token, api_secret=API_SECRET)
access_token = session["access_token"]

print("\nAccess Token:", access_token)

with open("access_token.txt", "w") as f:
f.write(access_token)

where I put the correct API key and API secret. When prompted, I pasted the request token. But an error appears. It says: -

kiteconnect.exceptions.TokenException: Token is invalid or has expired.

I used the request token within a few seconds after generation which is less than a minute. What di I do wrong.

Regards
Abhijit
  • salim_chisty
    You need to re-check if you are using the correct and fresh request_token from the redirect url and api_secret values.
    Please ensure you follow the login flow as outlined in the Kite Connect API documentation, and refer to this webinar walkthrough for a better understanding. Additionally, check the session FAQs here.
  • VKJ722
    I did not use kite api version 3 where sha of keys is required. Now I made it to work.
Sign In or Register to comment.