I'm using python client since last 2 months and my code was working fine.
today when I run the same code without any change, I get "kiteconnect.exceptions.TokenException"
I created new access token and tried.. token generated but getting the same error while fetching historical data..
what could be the problem?
  • sujith
    Did you create a new access token after subscribing to historical data?
    You can enable debug logs and see the exact error message and status code.
    Can you paste it here? Make sure to remove app and client-specific tokens.
  • ks_unni
    Traceback (most recent call last):
    File "C:\Code\SwingFinder\", line 67, in
    File "C:\Code\SwingFinder\", line 53, in get_data["15m"] = self.fetchOHLC("15minute",10).drop('volume', axis='columns')
    File "C:\Code\SwingFinder\", line 47, in fetchOHLC
    data = pd.DataFrame(self.kite.historical_data(self.token,,,interval))
    File "C:\Users\Admin\Anaconda3\envs\algo\lib\site-packages\kiteconnect\", line 627, in historical_data
    "oi": 1 if oi else 0
    File "C:\Users\Admin\Anaconda3\envs\algo\lib\site-packages\kiteconnect\", line 822, in _get
    return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)
    File "C:\Users\Admin\Anaconda3\envs\algo\lib\site-packages\kiteconnect\", line 894, in _request
    raise exp(data["message"], code=r.status_code)
    kiteconnect.exceptions.TokenException: Incorrect `api_key` or `access_token`.
  • ks_unni
    def get_data(self):["15m"] = self.fetchOHLC("15minute",10).drop('volume', axis='columns')["1d"] = self.fetchOHLC("day",30).drop('volume', axis='columns')
    print(str(self.symbol) + " - Data downloaded")

    def fetchOHLC(self,interval,duration):
    """extracts historical data and outputs in the form of dataframe"""
    data = pd.DataFrame(self.kite.historical_data(self.token,,,interval))
    if not data.empty:
    return data
  • ks_unni
    I create the access token in a separate program, which I call manually before executing this program..
    please help..
  • ks_unni
    Now its working without any change in code.. Strange behavior.. I didn't change the code nor I created any new access token..
  • sujith
    Can you check if the status code is 400 or 403? If it is 403 then can you private message the api_key and access token? we will check and get back to you.
  • ks_unni
    Now I'm not getting that error to check the status code.. I will contact you with status code if it appears again. Thank you.
  • ks_unni
    Hi Sujith, I'm getting status code 403 today.. sending my api_key and access token via private message..
  • ks_unni
    ks_unni edited April 2021
    Sorry!!.. it was my problem.. access token was generated in a different folder..
This discussion has been closed.