I am getting an error while access the historical price, however instrument list API returns the successful outcome. Below is my output where instrument tokens are being fetched and Historical Data API gives the error -
No, I am not doing that.. My Access Token is same since morning no matter how many time I generated with the Request Token.
process: 1. with api_key, api_secret get the request token 2. with request token get the access token def get_login(api_key, api_secret): global kws, kite kite = KiteConnect(api_key=api_key)
print("[*] Generate access token: ", kite.login_url()) request_tkn = input("[*] Enter your request token here: ") data = kite.generate_session(request_tkn, api_secret=api_secret) kite.set_access_token(data["access_token"]) kws = KiteTicker(api_key, data["access_token"]) print('Your Access Token is: ', data["access_token"])
get_login(api_key, api_secret)
3. use access token and api key to get the kite connection zerodha = Zerodha(api_key, access_token) kite_connect = zerodha.getKiteConnect()
4. call api on kite connection object data_df = pd.DataFrame( kite_connect.historical_data(instrument_token=instrument_token, from_date=CONST.from_date, to_date=CONST.to_date, interval=CONST.data_interval))
process:
1. with api_key, api_secret get the request token
2. with request token get the access token
def get_login(api_key, api_secret):
global kws, kite
kite = KiteConnect(api_key=api_key)
print("[*] Generate access token: ", kite.login_url())
request_tkn = input("[*] Enter your request token here: ")
data = kite.generate_session(request_tkn, api_secret=api_secret)
kite.set_access_token(data["access_token"])
kws = KiteTicker(api_key, data["access_token"])
print('Your Access Token is: ', data["access_token"])
get_login(api_key, api_secret)
3. use access token and api key to get the kite connection
zerodha = Zerodha(api_key, access_token)
kite_connect = zerodha.getKiteConnect()
4. call api on kite connection object
data_df = pd.DataFrame(
kite_connect.historical_data(instrument_token=instrument_token, from_date=CONST.from_date,
to_date=CONST.to_date,
interval=CONST.data_interval))
Is there anything wrong in the process ?
with this I get 403
0%| | 0/1 [00:00<?, ?it/s]DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "GET /instruments/historical/60417/day?from=2020-07-04+18%3A34%3A12&to=2025-07-03+18%3A34%3A12&interval=day&continuous=0&oi=0 HTTP/11" 403 None
Traceback (most recent call last):
File "/Users/sanoop/PycharmProjects/Anagha/com/com/rapid/execution.py", line 91, in <module>
joblib.Parallel(n_jobs=1)(
File "/opt/anaconda3/lib/python3.9/site-packages/joblib/parallel.py", line 1918, in __call__
return output if self.return_generator else list(output)
File "/opt/anaconda3/lib/python3.9/site-packages/joblib/parallel.py", line 1847, in _get_sequential_output
res = func(*args, **kwargs)
File "/Users/sanoop/PycharmProjects/Anagha/com/com/rapid/execution.py", line 34, in execute_for_equities
kite_connect.historical_data(instrument_token=instrument_token, from_date=CONST.from_date,
File "/opt/anaconda3/lib/python3.9/site-packages/kiteconnect/connect.py", line 632, in historical_data
data = self._get("market.historical",
File "/opt/anaconda3/lib/python3.9/site-packages/kiteconnect/connect.py", line 861, in _get
return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)
File "/opt/anaconda3/lib/python3.9/site-packages/kiteconnect/connect.py", line 937, in _request
raise exp(data["message"], code=r.status_code)
kiteconnect.exceptions.TokenException: Incorrect `api_key` or `access_token`.
0%| | 0/1 [00:00<?, ?it/s]
Process finished with exit code 1
is there any other way to enable debug logs of Kite Connect library ?
/opt/anaconda3/bin/python /Users/sanoop/PycharmProjects/Anagha/com/com/rapid/zerodha_connect.py
[*] Generate access token: https://kite.zerodha.com/connect/login?api_key=*************&v=3
[*] Enter your request token here: ******FromURL**********
DEBUG:kiteconnect.connect:Request: POST https://api.kite.trade/session/token {'api_key': '*********', 'request_token': '***********', 'checksum': 'cfc352098968cdf81697056cc3d264626e2f337118425fe951bcc9d4285c8f02'} {'X-Kite-Version': '3', 'User-Agent': 'Kiteconnect-python/5.0.1'}
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /session/token HTTP/11" 200 None
DEBUG:kiteconnect.connect:Response: 200 b'{"status":"success","data":{"user_type":"individual/res_no_nn","email":"san****.****@gmail.com","user_name":"Sanoop Kumar Yadav","user_shortname":"Sanoop","broker":"ZERODHA","exchanges":["NSE","BSE","NFO","MF"],"products":["CNC","NRML","MIS","BO","CO"],"order_types":["MARKET","LIMIT","SL","SL-M"],"avatar_url":null,"user_id":"*******","api_key":"lqly78z223hbmgs3","access_token":"********","public_token":"CduL55L2G5cniQV18MdcQIchtlOufzvL","refresh_token":"","enctoken":"****************","login_time":"2025-07-04 13:26:34","meta":{"demat_consent":"physical"}}}'
Your Access Token is: **************Generated****************