Invalid session credentials

krishnanm2006
HI all,
I am facing the following error while retrieving access token

File "C:\Users\admin\Anaconda3\lib\site-packages\kiteconnect\__init__.py", line 684, in _request
raise(exp(data["message"], code=r.status_code))

TokenException: Invalid session credentials



Code that i used to get the token as below.... pls help .. thanks

from kiteconnect import KiteConnect

api_key ='yy'
api_secret ='zzz'

kite=KiteConnect(api_key,api_secret)
kite.login_url()

kite.request_access_token('XXXXX',api_secret)


  • sujith
    You seem to be using old API. I would suggest migrating to Kite Connect 3 APIs. You can check out more details here.

    You can check out more details about the TokenException here.
  • krishnanm2006
    hi Sujit, thanks !

    now i am getting the below error

    AttributeError: 'KiteConnect' object has no attribute 'generate_session'
  • sujith
    Can you let us know the pykiteconnect version you are using?
  • krishnanm2006
    am i using a redundant version?? if yes then kindly help me how to upgrade it with a newer one..

    thank you !
  • krishnanm2006

    I tried using the command - pip install kiteconnect --upgrade --pre
    however it still is giving me the same version.. @sujith pls help !!!!



  • krishnanm2006
    I upgraded my API version... however i get the following error now...

    TokenException: Token is invalid or has expired.

    File "", line 1, in
    runfile('C:/Users/admin/Desktop/KiteConnect/Connection_attempt.py', wdir='C:/Users/admin/Desktop/KiteConnect')

    File "C:\Users\admin\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
    execfile(filename, namespace)

    File "C:\Users\admin\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

    File "C:/Users/admin/Desktop/KiteConnect/Connection_attempt.py", line 29, in
    data = kite.generate_session(public_token, api_secret)

    File "C:\Users\admin\Anaconda3\lib\site-packages\kiteconnect-3.7.0b10-py3.6.egg\kiteconnect\connect.py", line 228, in generate_session
    "checksum": checksum

    File "C:\Users\admin\Anaconda3\lib\site-packages\kiteconnect-3.7.0b10-py3.6.egg\kiteconnect\connect.py", line 697, in _post
    return self._request(route, "POST", params)

    File "C:\Users\admin\Anaconda3\lib\site-packages\kiteconnect-3.7.0b10-py3.6.egg\kiteconnect\connect.py", line 762, in _request
    raise exp(data["message"], code=r.status_code)

    TokenException: Token is invalid or has expired.
  • krishnanm2006
    hi this got resolved
This discussion has been closed.