not able to generate access token for KiteConnect

bhupeniitd01
getting the below error every time entering request token.

TokenException Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_22456/1764517594.py in
1 kite = KiteConnect(api_key=api_key)
----> 2 data=kite.generate_session(request_token, api_secret=api_secret)
3
4 print(data)

~\anaconda3\lib\site-packages\kiteconnect\connect.py in generate_session(self, request_token, api_secret)
256 checksum = h.hexdigest()
257
--> 258 resp = self._post("api.token", params={
259 "api_key": self.api_key,
260 "request_token": request_token,

~\anaconda3\lib\site-packages\kiteconnect\connect.py in _post(self, route, url_args, params, is_json, query_params)
839 def _post(self, route, url_args=None, params=None, is_json=False, query_params=None):
840 """Alias for sending a POST request."""
--> 841 return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
842
843 def _put(self, route, url_args=None, params=None, is_json=False, query_params=None):

~\anaconda3\lib\site-packages\kiteconnect\connect.py in _request(self, route, method, url_args, params, is_json, query_params)
911 # native Kite errors
912 exp = getattr(ex, data.get("error_type"), ex.GeneralException)
--> 913 raise exp(data["message"], code=r.status_code)
914
915 return data["data"]

TokenException: Token is invalid or has expired.
  • bhupeniitd01
    Zerodha Admins pls help
  • SRIJAN
    A request token is valid only for a couple of minutes. After that ,it expires.
  • bhupeniitd01
    hi srijan, i am entering request token immediately, within few seconds. still getting the same error.
  • sujith
    You can run with debug logs enabled and check, if the values that is being sent are correct. It is working fine at our end.
  • sujith
    A request token can be used only once and is valid for a couple of minutes.
  • bhupeniitd01
    i am aware of the usage of request token and doing it rightly. i tried again with the below code and getting the same error.

    #!python
    import logging
    from kiteconnect import KiteConnect

    logging.basicConfig(level=logging.DEBUG)

    kite = KiteConnect(api_key="hjnl154ozm******")
    data = kite.generate_session("itMnbneaEVTlh3b2lekVRtRl7cJBRGye", api_secret="qmqmjtg1htqzz1p3xld2******")
    kite.set_access_token(data["access_token"])
    print(data)


    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
    911 # native Kite errors
    912 exp = getattr(ex, data.get("error_type"), ex.GeneralException)
    --> 913 raise exp(data["message"], code=r.status_code)
    914
    915 return data["data"]

    TokenException: Token is invalid or has expired.
  • sujith
    can you private message the api_key?
  • bhupeniitd01
    zerodha admin:- My problem is still unresolved.
  • sujith
    sujith edited April 2022
    Kite Connect is purely an execution platform. We don't provide one to one support for Kite Connect. This is a community driven forum. We are not support agents. We are all developers who work on our projects and take out some time to help out fellow developers.

    PS: Kite Connect is being used by thousands of apps in production, if it has any issues then this forum will be flooded with queries.
Sign In or Register to comment.