Please help me in getting the access token from request access code. I used the code:
from kiteconnect import KiteConnect import logging # Redirect URL specified in your Kite Connect app settings redirect_url = "YOUR_REDIRECT_URL" logging.basicConfig(level=logging.DEBUG) # Initialize KiteConnect instance kite = KiteConnect('xxxx')
# Get the authorization URL login_url = kite.login_url()
# Redirect the user to the login URL print("Please login to Zerodha and grant permission:") print(login_url)
# After successful login and permission, get the request token request_token = input("Enter the request token: ") data = kite.generate_session(request_token=request_token, api_secret='yyy')
# Get the access token access_token = data["access_token"]
# Print the access token print("Access Token:", access_token)
The error i got from using this code: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443 DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /session/token HTTP/1.1" 403 None Traceback (most recent call last): File "access_token.py", line 19, in data = kite.generate_session(request_token=request_token, api_secret='yyyy') File "venv\lib\site-packages\kiteconnect\connect.py", line 262, in generate_session resp = self._post("api.token", params={ File "venv\lib\site-packages\kiteconnect\connect.py", line 855, in _post return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json, query_params=query_params) File "venv\lib\site-packages\kiteconnect\connect.py", line 927, in _request raise exp(data["message"], code=r.status_code) kiteconnect.exceptions.TokenException: Token is invalid or has expired.