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?
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.
Traceback (most recent call last): File "C:\Code\SwingFinder\SwingFinder.py", line 67, in fno_instruments[str(instrument)].get_data() File "C:\Code\SwingFinder\instrument.py", line 53, in get_data self.data["15m"] = self.fetchOHLC("15minute",10).drop('volume', axis='columns') File "C:\Code\SwingFinder\instrument.py", line 47, in fetchOHLC data = pd.DataFrame(self.kite.historical_data(self.token,dt.date.today()-dt.timedelta(duration), dt.date.today(),interval)) File "C:\Users\Admin\Anaconda3\envs\algo\lib\site-packages\kiteconnect\connect.py", line 627, in historical_data "oi": 1 if oi else 0 File "C:\Users\Admin\Anaconda3\envs\algo\lib\site-packages\kiteconnect\connect.py", 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\connect.py", line 894, in _request raise exp(data["message"], code=r.status_code) kiteconnect.exceptions.TokenException: Incorrect `api_key` or `access_token`.
def fetchOHLC(self,interval,duration): """extracts historical data and outputs in the form of dataframe""" time.sleep(0.15) data = pd.DataFrame(self.kite.historical_data(self.token,dt.date.today()-dt.timedelta(duration), dt.date.today(),interval)) if not data.empty: data.set_index("date",inplace=True) return data
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.
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.
File "C:\Code\SwingFinder\SwingFinder.py", line 67, in
fno_instruments[str(instrument)].get_data()
File "C:\Code\SwingFinder\instrument.py", line 53, in get_data
self.data["15m"] = self.fetchOHLC("15minute",10).drop('volume', axis='columns')
File "C:\Code\SwingFinder\instrument.py", line 47, in fetchOHLC
data = pd.DataFrame(self.kite.historical_data(self.token,dt.date.today()-dt.timedelta(duration), dt.date.today(),interval))
File "C:\Users\Admin\Anaconda3\envs\algo\lib\site-packages\kiteconnect\connect.py", line 627, in historical_data
"oi": 1 if oi else 0
File "C:\Users\Admin\Anaconda3\envs\algo\lib\site-packages\kiteconnect\connect.py", 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\connect.py", line 894, in _request
raise exp(data["message"], code=r.status_code)
kiteconnect.exceptions.TokenException: Incorrect `api_key` or `access_token`.
self.data["15m"] = self.fetchOHLC("15minute",10).drop('volume', axis='columns')
self.data["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"""
time.sleep(0.15)
data = pd.DataFrame(self.kite.historical_data(self.token,dt.date.today()-dt.timedelta(duration), dt.date.today(),interval))
if not data.empty:
data.set_index("date",inplace=True)
return data
please help..