Same access_key being generated (expired / invalid)

Piyush_Gehlot

key.py

from kiteconnect import KiteConnect
API_KEY = "123456789"
kite = KiteConnect(api_key=API_KEY)

print(kite.login_url())
I then take the key from the browser link and paste it in fetch-token.py

fetch-token.py

from kiteconnect import KiteConnect

API_KEY = "123456789"
API_SECRET = "123456789"
REQUEST_TOKEN = "Xv4oavF0H4DGh" # From the browser URL

kite = KiteConnect(api_key=API_KEY)
data = kite.generate_session(REQUEST_TOKEN, api_secret=API_SECRET)

# Extract and save access token
access_token = data["access_token"]
print("✅ New Access Token:", access_token)

# ???? Overwrite existing token file
with open("access_token.txt", "w") as f:
f.write(access_token)
upon running fetch-token.py, i store the newly generated access token in access_token.txt. I used to do this in the morning and it would run the entire day. however since last 2 days i am getting an error, Invalid `api_key` or `access_token` when i try to place a trade. I noticed that the access token that i generate every time is the same (the code doesn't change).

  • salim_chisty
    Please double-check the request token and API key you entered for the login flow. You can refer to the similar discussion here.
    If the issue persists, please enable debug mode and share the complete stack trace here.
Sign In or Register to comment.