I am not getting access token

Afzalur
Dear Friends
I am new for this trading platform.
I have zerodha account and bought 2000 credit and want to test the automatic trading through python code.


Following code worked properly

import logging
from kiteconnect import KiteConnect
logging.basicConfig(level=logging.DEBUG)
kite = KiteConnect(api_key="xxxxxxxxxxxxxx")


Blew code is showing error
data = kite.generate_session("access_token", api_secret="xxxxxxxxxxxxxxxxxxxxxxx")
kite.set_access_token(data["access_token"])

This is the error
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

TokenException Traceback (most recent call last)
in
----> 1 data = kite.generate_session("access_token", api_secret="xxxxxxxxxxxxxxxxxxxxxxxx")
2 kite.set_access_token(data["access_token"])

C:\ProgramData\Anaconda\Anaconda3\lib\site-packages\kiteconnect-3.7.7-py3.7.egg\kiteconnect\connect.py in generate_session(self, request_token, api_secret)
230 "api_key": self.api_key,
231 "request_token": request_token,
--> 232 "checksum": checksum
233 })
234

C:\ProgramData\Anaconda\Anaconda3\lib\site-packages\kiteconnect-3.7.7-py3.7.egg\kiteconnect\connect.py in _post(self, route, params)
699 def _post(self, route, params=None):
700 """Alias for sending a POST request."""
--> 701 return self._request(route, "POST", params)
702
703 def _put(self, route, params=None):

C:\ProgramData\Anaconda\Anaconda3\lib\site-packages\kiteconnect-3.7.7-py3.7.egg\kiteconnect\connect.py in _request(self, route, method, parameters)
764 # native Kite errors
765 exp = getattr(ex, data["error_type"], ex.GeneralException)
--> 766 raise exp(data["message"], code=r.status_code)
767
768 return data["data"]

TokenException: Token is invalid or has expired.
Sign In or Register to comment.