Unable to get the access token for the app

VSingham
Hi guys
I am unable to get the access token for my app in python. This is my first app on kite connect, and I am also new to coding. I checked the documentation and tried to following the instructions but am getting stuck here, so would appreciate the help.

The document says in order to get the access token we have to:

POST the api_key, request_token and checksum (SHA-256 of api_key + request_token + api_secret) to /session/token

by using the following command:

curl https://api.kite.trade/session/token \
-H "X-Kite-Version: 3" \
-d "api_key=xxx" \
-d "request_token=yyy" \
-d "checksum=zzz"

I am getting errors again and again, so here are my questions:
1. Whats the best way to calculate the checksum here? Do I have to concatenate the api_key, request_token and api_secret into one string and then find the checksum of the combined string
2. Can I calculate this checksum in python, whats the code for it
3. Are the entire 5 lines of code starting with curl https://... above to be pasted exactly as they are shown above? Is this to be done in python or in the main terminal after exiting from python?

Please let me know. Thanks
  • sujith
    You don't have to do all these.
    pykiteconnect does it for you. You can check out the repo here.
  • VSingham
    Hi, I'm already using kiteconnect. The recommended code I sent above is from the documentation of the API. Am I missing something?
  • sujith
    You can use the generate session method.
  • VSingham
    Thanks. I tried to fix the program and run it again but its giving me the following error. Can you pl guide me as to whats wrong:

    EBUG: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" 200 None

    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

    403 Forbidden
  • sujith
    You can refer to this thread.
  • VSingham
    Thanks, but I am just not able to go past this step - I am doing something wrong in generating a session I think, but am not sure. Here is what I get in my terminal if I try to run the script step by step and reach this command and press enter:
    data = kite.generate_session(request_token, api_secret=api_secret)

    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" 200 None
  • sujith
    Did you print the data?
  • VSingham
    Sorry, which data
  • VSingham
    If you're talking of the data that the server sends if the script works well, (name, exchanges the user has access, access token etc), no I didnt get that. I just got the error messages above
  • rakeshr
    @VSingham
    "POST /session/token HTTP/1.1" 200 None
    Session post request is succesfull. Can you paste here complete access_token generation part of your code? We will take look at it.
Sign In or Register to comment.