TokenException: Incorrect `api_key` or `access_token`.

Qber89
I have been trying to read historical data. By using the API key and access token i am able to fetch the instrument details but the moment i run the code to fetch the data it says invalid key, access token. I have verified multiple times that the key and token are correct however just when i run the code to fetch the data it fails.. any suggestions please.. I am new to this and feeling very overwhelmed....




File ~\anaconda3\Lib\site-packages\kiteconnect\connect.py:937, in KiteConnect._request(self, route, method, url_args, params, is_json, query_params)
935 # native Kite errors
936 exp = getattr(ex, data.get("error_type"), ex.GeneralException)
--> 937 raise exp(data["message"], code=r.status_code)
939 return data["data"]
940 elif "csv" in r.headers["content-type"]:

TokenException: Incorrect `api_key` or `access_token`.
  • nagavenij
    You may refer to this forum discussion.
  • Qber89
    Thanks nagavenij, are you an independent trader? or from Zerodha? wondering if we can collaborate for further learning?
  • Ghost6
    There are 2 things you need to improve. the Date formatting is wrong:

    : %M: %S")

    and best practices is to keep a token mapping with instrument name, instrument tokens have to be updated everyday with their insrument name. going forward start implementing them right away. Also create a config file which you load for data fetch so that you dont have to update your script with access token and api key or secret api. rest all looks fine
Sign In or Register to comment.