It looks like you're new here. If you want to get involved, click one of these buttons!
DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /session/token HTTP/1.1" 403 None
Traceback (most recent call last):
File "<ipython-input-1-ea6aa0483439>", line 1, in <module>
runfile('/Users/mgz1985/OneDrive/Zerodha/zerodha_mcx.py', wdir='/Users/mgz1985/OneDrive/Zerodha')
File "/opt/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "/opt/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/Users/mgz1985/OneDrive/Zerodha/zerodha_mcx.py", line 25, in <module>
access_token = kite.generate_session(kite.login_url(), api_secret = api_private)
File "/Users/mgz1985/OneDrive/Zerodha/kiteconnect/connect.py", line 255, in generate_session
"checksum": checksum
File "/Users/mgz1985/OneDrive/Zerodha/kiteconnect/connect.py", line 824, in _post
return self._request(route, "POST", params)
File "/Users/mgz1985/OneDrive/Zerodha/kiteconnect/connect.py", line 889, in _request
raise exp(data["message"], code=r.status_code)
TokenException: Token is invalid or has expired.
PS: I have already watched the webinar from 2017 (https://kite.trade/forum/discussion/2005/invalid-checksum), but the method is not valid in v3.
h = hashlib.sha256(self.api_key.encode("utf-8") + request_token.encode("utf-8") + api_secret.encode("utf-8"))
checksum = h.hexdigest()
resp = self._post("api.token", {
"api_key": self.api_key,
"request_token": request_token,
"checksum": checksum
})
if "access_token" in resp:
self.set_access_token(resp["access_token"])
My doubt is how is 'access_token' been created in the dictionary 'resp'
{"status":"error","message":"Invalid `api_key`","data":null,"error_type":"InputException"}
My API Key is correct. Does someone know how to get this resolved or not?
Above pasted code seems to be incomplete. As we don't see data variable used for access_token being assigned anywhere.
# 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.
request_token = kite.login_url() # This value must be stored in database in the dataframe for daily
print(request_token)
data = kite.generate_session(request_token, api_secret = api_private) # api_private is the secret api
kite.set_access_token(data[access_token])
user is not authorised on App
. Even you can check for all permitted app on Kite web under App section. Are you not getting an access_token or you are getting access_token but set_access_token is generating error?kite.set_access_token(data[access_token])
In regards to the access_token, when I run print(data), this. is what I get:
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
I think at my end everything is good now. Do you have any further suggestions?
print(data)
should return this user_detail response, which will have"access_token"
field. From that's what you are extracting access_token heredata['access_token']
If you see the details in the error posted, the throwback is related to checksum.