Problem with access token request

asskg32
I have used the follwing code:


>>> from kiteconnect import KiteConnect

>>> api_key = "api_key"
>>> api_secret = "api_secret"

>>> kite = KiteConnect(api_key=api_key)

>>> print kite.login_url()
https://kite.trade/connect/login?api_key=xxxxxxxxxxxxx

>>> kite.request_access_token("t6fresv8u4cjly8zidzfu88j3rlm0tb2", secret=api_secret)

TokenException Traceback (most recent call last)
in ()
----> 1 data = kite.request_access_token("t6fresv8u4cjly8zidzfu88j3rlm0tb2", secret=api_secret)

C:\Users\anurag\Anaconda2\lib\site-packages\kiteconnect\__init__.pyc in request_access_token(self, request_token, secret)
213 resp = self._post("api.validate", {
214 "request_token": request_token,
--> 215 "checksum": checksum
216 })
217

C:\Users\anurag\Anaconda2\lib\site-packages\kiteconnect\__init__.pyc in _post(self, route, params)
444 def _post(self, route, params=None):
445 """Alias for sending a POST request."""
--> 446 return self._request(route, "POST", params)
447
448 def _put(self, route, params=None):

C:\Users\anurag\Anaconda2\lib\site-packages\kiteconnect\__init__.pyc in _request(self, route, method, parameters)
526 code=r.status_code))
527 elif exp:
--> 528 raise(exp(data["message"], code=r.status_code))
529 else:
530 raise(ex.GeneralException(data["message"], code=r.status_code))

TokenException: Invalid checksum


What is it that I am doing wrong? Need Help! :smile: )
  • Vivek
    @asskg32 Please check if you are setting correct api_secret while exchanging request token for access token. It may also possible that you didn't use correct request token. Please make sure you have obtained request_token from the your redirect url after Kite login is successful. Check login flow here - https://kite.trade/docs/connect/v1/#login-flow
  • asskg32
    Yes I had an extra space in my api secret! Now it is working. :sweat_smile: Thanks and thanks for such an awesome initiative for providing us with programmatic access :smile:
This discussion has been closed.