I am new to kiteconnect api. Using below code to authenticate kiteconnect api, however I am receiving Token invalid or expired error. Could you please advise.
######################### CODE #################################### from kiteconnect import KiteConnect
obtained_request_token = "XXXXXX" data = kite.generate_session(obtained_request_token, api_secret=api_secret) ####################### ERROR ######################################## #python kconnect.py Traceback (most recent call last): File "kconnect.py", line 11, in data = kite.generate_session(obtained_request_token, api_secret=api_secret) File "/home/tatis/anaconda3/envs/Trade/lib/python3.8/site-packages/kiteconnect/connect.py", line 252, in generate_session resp = self._post("api.token", params={ File "/home/tatis/anaconda3/envs/Trade/lib/python3.8/site-packages/kiteconnect/connect.py", line 826, in _post return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json) File "/home/tatis/anaconda3/envs/Trade/lib/python3.8/site-packages/kiteconnect/connect.py", line 894, in _request raise exp(data["message"], code=r.status_code) kiteconnect.exceptions.TokenException: Token is invalid or has expired.
I have followed the thread, I understand the request token, I have opened the login.url() in browser and got the request token, but when I supplied the request token, I am getting the error.
Enter request token:I2Ul3tsJtXSOYp0Lk6AK0BxdteNWTdLO <= Supplied request token here, but failed
Traceback (most recent call last): File "kconnect.py", line 10, in <module> data = kite.generate_session(obtained_request_token, api_secret=api_secret) File "/home/tatis/anaconda3/envs/Trade/lib/python3.8/site-packages/kiteconnect/connect.py", line 252, in generate_session resp = self._post("api.token", params={ File "/home/tatis/anaconda3/envs/Trade/lib/python3.8/site-packages/kiteconnect/connect.py", line 826, in _post return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json) File "/home/tatis/anaconda3/envs/Trade/lib/python3.8/site-packages/kiteconnect/connect.py", line 894, in _request raise exp(data["message"], code=r.status_code) kiteconnect.exceptions.TokenException: Token is invalid or has expired.
I have followed the thread, I understand the request token, I have opened the login.url() in browser and got the request token, but when I supplied the request token, I am getting the error.
#python kconnect.py
https://kite.trade/connect/login?api_key=XXXXXXXXXXX&v=3 ==> Opened this in browser and got request token
##################
Here is how I received the request token in browser:
http://127.0.0.1/?request_token=I2Ul3tsJtXSOYp0Lk6AK0BxdteNWTdLO&action=login&status=success
################
Enter request token:I2Ul3tsJtXSOYp0Lk6AK0BxdteNWTdLO <= Supplied request token here, but failed
Traceback (most recent call last):
File "kconnect.py", line 10, in <module>
data = kite.generate_session(obtained_request_token, api_secret=api_secret)
File "/home/tatis/anaconda3/envs/Trade/lib/python3.8/site-packages/kiteconnect/connect.py", line 252, in generate_session
resp = self._post("api.token", params={
File "/home/tatis/anaconda3/envs/Trade/lib/python3.8/site-packages/kiteconnect/connect.py", line 826, in _post
return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json)
File "/home/tatis/anaconda3/envs/Trade/lib/python3.8/site-packages/kiteconnect/connect.py", line 894, in _request
raise exp(data["message"], code=r.status_code)
kiteconnect.exceptions.TokenException: Token is invalid or has expired.
You may refer to this thread.