I am unable to login using the sample code shared in the Python client documentation. My redirect URL is set to http://127.0.0.1
I tried firing the URL https://kite.zerodha.com/connect/login?api_key=my_api_key from my browser and get the reply { "error_type": "ForbiddenError", "message": "Invalid api_key", "status": "error" } Note: I have already double checked the api_key.
I am using requests library to make the query and following is the code snippet and its output.
Code kite = KiteConnect(api_key=self.__api_key)
# Redirect the user to the login url obtained # from kite.login_url(), and receive the request_token # from the registered redirect url after the login flow. # Once you have the request_token, obtain the access_token # as follows.
@ssmaitra Your app 'CountXTreme' which you tried to create is in pending state, it might be because some error while creating the app or making payments. I checked payment history and there were no payments made yet so please kindly add credits and activate the app.
I am getting the error Insufficient balance. Please add funds to your Zerodha account. I have much more that the required 2000 credits in my Zerodha account. Can you check please?
@ssmaitra User login flow is mandatory to obtain access_token and we can't provide full automation for that. You can check tool like selenium for that.
Hi @ssmaitra You can use python mechanize library to automate your obtaining request token and generating access token business. Its quite simple and takes around 7-11 secs to generate an access token.
I am able to successfully submit this form and get a response on redirect url using selenium and python, I have a problem though that it start asking to launch kite app on mobile and key in 6 digit OTP, for algo trading this wont be possible to do, can you suggest a way out.
Also, for retail algo traders is there a plan to disable this web browser dependency for login and make it pure rest api based with token refresh etc. ?
Code
kite = KiteConnect(api_key=self.__api_key)
# Redirect the user to the login url obtained
# from kite.login_url(), and receive the request_token
# from the registered redirect url after the login flow.
# Once you have the request_token, obtain the access_token
# as follows.
print 'Login url: ', kite.login_url()
response = requests.get(kite.login_url(), allow_redirects=False)
print 'Status code: ', response.status_code
print 'Headers: ', response.headers
print 'History: ', response.history
print 'Reason: ', response.raw.reason
print 'Redrect url: ', response.headers['location']
Output
Login url: https://kite.trade/connect/login?api_key=09y9sc1765udoxpb
Status code: 302
Headers: CaseInsensitiveDict({'content-length': '154', 'server': 'nginx', 'connection': 'keep-alive', 'location': 'https://kite.zerodha.com/connect/login?api_key=09y9sc1765udoxpb', 'date': 'Wed, 06 Jul 2016 19:30:37 GMT', 'content-type': 'text/html'})
History: []
Reason: Moved Temporarily
Redrect url: https://kite.zerodha.com/connect/login?api_key=09y9sc1765udoxpb
If you notice, the redirect URL does not contain the request_token. Can you check where could be the problem ?
Login url: https://kite.trade/connect/login?api_key=09y9sc1765udoxpb
Status code: 302
Headers: CaseInsensitiveDict({'content-length': '154', 'server': 'nginx', 'connection': 'keep-alive', 'location': 'https://kite.zerodha.com/connect/login?api_key=09y9sc1765udoxpb', 'date': 'Thu, 07 Jul 2016 17:27:55 GMT', 'content-type': 'text/html'})
History: []
Reason: Moved Temporarily
Redrect url: https://kite.zerodha.com/connect/login?api_key=09y9sc1765udoxpb
How do I log in automatically without prompting for login page? BTW, I will be storing passwords in a secure password vault.
access_token
and we can't provide full automation for that. You can check tool like selenium for that.sampe code -
kite = KiteConnect(api_key)
#xyz = kite.login_url()
#print "kite" ,kite
#browser= mechanize.Browser()
#browser.add_password('https://kite.trade/connect/login?api_key=xxxx', 'xxxx', 'xxxx')
#response = browser.open('https://kite.trade/connect/login?api_key=xxxx')
#xyz = response.geturl()
#print xyz
#request_token =xyz[47:79]
#print request_token
It is mandatory by the exchange that a user has to login manually at least once a day. We don't recommend automating login.