I have been using below code to generate an kite object. Code used to work 3 days back, but has started giving error . have checked kite.trade, API keys are set to expire on 12 June. Could not figure out reason. Can somebody help @sujith
time generated : 2022-06-03 10:14:53 Traceback (most recent call last): File "/Users/madhavg/Documents/python_fun/blackpearl/Kite_Connect.py", line 164, in quote = kite.quote("NSE:INFY") File "/Users/madhavg/opt/anaconda3/envs/kite/lib/python3.8/site-packages/kiteconnect/connect.py", line 577, in quote data = self._get("market.quote", params={"i": ins}) File "/Users/madhavg/opt/anaconda3/envs/kite/lib/python3.8/site-packages/kiteconnect/connect.py", line 842, in _get return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json) File "/Users/madhavg/opt/anaconda3/envs/kite/lib/python3.8/site-packages/kiteconnect/connect.py", line 918, in _request raise exp(data["message"], code=r.status_code) kiteconnect.exceptions.TokenException: Incorrect `api_key` or `access_token`.
-- Python code
from kiteconnect import KiteConnect import logger import os from dotenv import load_dotenv from selenium import webdriver import time import os from selenium import webdriver import datetime as dt from urllib import parse from furl import furl
mylogger = logger.get_logger("Kite_Connect")
class Kite_Connect: def __init__(self):
if self.should_generate_fresh_token(): mylogger.debug("generating access token and request token") self.autologin() self.kite = self.get_access()
def __repr__(self): return "Kite Connect"
def should_generate_fresh_token(self): if "time_generated" in os.environ: time_generated = dt.datetime.strptime( os.environ.get("time_generated"), "%Y-%m-%d %H:%M:%S" ) print ("time generated : ", time_generated) else: time_generated = dt.datetime(1970, 1, 1, 0, 0, 0, 0) today = dt.datetime.now() refresh_threshold = dt.datetime(today.year, today.month, today.day, 4,0,0) if ( (time_generated < refresh_threshold) or (os.environ.get("access_token") is None) or (os.environ.get("request_token") is None) ): return True else: return False