Token Exception

rjv17
rjv17 edited July 2018 in Python client
I am using :
data = kite.generate_session and
kite.set_access_token(data["access_token"]) method given in the procedure.

I am getting this:
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 "testKite.py", line 10, in
data = kite.generate_session("********", api_secret=api_secret)
File "build/bdist.macosx-10.14-intel/egg/kiteconnect/connect.py", line 232, in generate_session
File "build/bdist.macosx-10.14-intel/egg/kiteconnect/connect.py", line 701, in _post
File "build/bdist.macosx-10.14-intel/egg/kiteconnect/connect.py", line 766, in _request
kiteconnect.exceptions.TokenException: Token is invalid or has expired.

My client ID : XX9317
  • rakeshr
    @rjv17
    Are you calling generate session multiple times?
    A request token is valid for a couple of minutes and validity is once. The access token is valid for one day.Once you get access token store it and reuse it..
  • rjv17
    I am using it only once. Actually I dont think this is the problem. I dont see a request_token in URL. All I see is a sess_id and apikey. I am currently using the sess_id as the request token, and this can be the issue. How do I get a request token?
  • rakeshr
    @rjv17
    If you have done successful login, you will get request token in redirect url,something like this,
    http://127.0.0.1:8000(your redirect url)/action=login&status=success&request_token=XXXXXXXXXXXXXX.
    Have a look to login flow part on documentation.
  • rjv17
    rjv17 edited July 2018
    @rakeshr:
    This is what it looks like:
    https://kite.zerodha.com/connect/authorize?sess_id=XXXXXXXXXX&api_key=XXXXXXXXXXX
    before authorizing.


    Can I my kite app on phone logged-in while doing this?
    Also, will the money be debited multiple times if I delete the existing app and create a new one ?
  • rakeshr
    @rjv17
    https://kite.zerodha.com/connect/authorize?sess_id=XXXXXXXXXX&api_key=XXXXXXXXXXX
    Above url will be there before login(initial page), after login authorization(make sure, you login with client id, entered in Connect app account), it will be with request_token:
    http://127.0.0.1:8000(your redirect url)/action=login&status=success&request_token=XXXXXXXXXXXXXX.
    Can I my kite app on phone logged-in while doing this?
    Yeah, but you should not log out, as it will destroy session of Connect App as well.
    Also, will the money be debited multiple times if I delete the existing app and create a new one ?
    Yes, your credit will be gone.Why you want to delete, you can make changes accordingly.
  • rjv17
    @rakeshr :
    I was able to connect.
    I have deleted and created multiple apps. billings show that money is deposited and debited multiple times. Have I lost all that money?
  • rjv17
    @rakeshr :

    I subscribed to historical data as well.
    But I am constantly getting this message ."Insufficient permission for that call"
    Other scripts with same tokens are working.
Sign In or Register to comment.