Sample python code to get the access token

Praveen_Tyagi
Hi Guys,
After logging in manually on kite.zerodha.

When I type following url on browser(https://kite.trade/connect/login?api_key=xxx) it redirects me to 127.0.0.1/?status=success&request_token=zzzz and then I could manually copy this token for further processing but when I perform the same thing programmatically my request is not being directed to 127.0.0.1/?zzzzzzzzzzz.

Here is my sample program.
import requests
url = 'https://kite.trade/connect/login?api_key=xxx'
resp = requests.post(url)
r.text

But i don't get same response back. I am new to Kiteconnect. Could you please help me resolving this problem probably some sample code?

Thanks in advance

Praveen Tyagi
  • sujith
    Hi @Praveen_Tyagi,

    It is mandatory by exchange that user has to login manually. Don't automate login.
  • Praveen_Tyagi
    @sujith ; I am not trying to automate the login but the extraction of access_code, which is required to communicate with kiteconnect.

    I always manually login and answer security question before running my script. So i am always logged in via browser. I can get the access_code manually and pass that to my script. But currently i am not running my script continuously but I run my script make some changes and re-run my script. In order to run 2nd time I have to collect the token once again manually and pass new token to script. That is a bit annoying . I was thinking of automating 'Collection of Access Code'.

    If it is still not clear please provide me a suitable number to reach you guys. Would love to give you a call to discuss this.

    Thanks


  • sujith
    @Praveen_Tyagi,

    Just store access token, why do you have to fetch it every time.
  • Praveen_Tyagi
    @sujith - It is invalidating that token and give us 'invalid credentials error ' if I stop my debugger and re-run the script. again. Probably because when i run it again it spawns a new process.

  • Praveen_Tyagi
    guys any update here.
  • sujith
    Hi Pradeep,
    Don't request for access token every time you run script. You should do it only once.
  • Praveen_Tyagi
    @sujith : Thanks for your help. But looks like you didn't read my comment carefully.

    If i don't fetch new request token (manually) every time before starting my script then i am getting 'invalid credentials error '.

    Since i am still in the design phase so i have to run my code to test the output and then change the code to deal with response etc. It is very annoying to copy paste the url to browser and then manually copy request token to my code.

    Is there no way i can get token programmatically after logging in manually via browser.

    Is there a way i can reach you for faster resolution. Because it is taking too much time.

  • sujith
    Hi Pradeep,
    I got your point. Here is what I would suggest, once you get your
    request token. You can use it to get access token. After you get access token, store it in DB or any other storage. Reuse the same access token till it expires. Don't make call to get access token every time you run your script.
Sign In or Register to comment.