incorrect api key or access token

Ashok121
While running python coding, I am getting following error: Can anybody help me?

kiteconnect.exceptions.TokenException: Incorrect `api_key` or `access_token`.
  • sujith
    Your access token might be expired. You need to fetch new access token.
  • Ashok121
    I generated new access token 2 mins back and still getting same below problem while running python coding.

    (kite3) 01:22 ~/tisha $ python kite3.py
    Traceback (most recent call last):
    File "kite3.py", line 6, in
    print(kite.ltp("NSE:INFY"))
    File "/home/Tisha1806/.virtualenvs/kite3/local/lib/python3.6/site-packages/kiteconnect/connect.py", line 571, in ltp
    return self._get("market.quote.ltp", {"i": ins})
    File "/home/Tisha1806/.virtualenvs/kite3/local/lib/python3.6/site-packages/kiteconnect/connect.py", line 693, in _get
    return self._request(route, "GET", params)
    File "/home/Tisha1806/.virtualenvs/kite3/local/lib/python3.6/site-packages/kiteconnect/connect.py", line 762, in _request
    raise exp(data["message"], code=r.status_code)
    kiteconnect.exceptions.TokenException: Incorrect `api_key` or `access_token
  • Ashok121
    Dear Sujith,

    For your information, I am running below python coding when I get above problem: let me know any issue of coding in that.

    from kiteconnect import KiteConnect
    api_key=open('api_key.txt','r').read()
    api_secret=open('api_secret.txt','r').read()
    kite=KiteConnect(api_key=api_key)
    kite.set_access_token(open('access_token.txt','r').read())
    print(kite.ltp("NSE:INFY"))
  • sujith
    @Ashok121,
    Are you using Pi or NEST?
  • Ashok121
    I am running code through python 3.6 on pythonanywhere.com.
    And access token through kite Zerodha
  • Ashok121
    does access and request token are different?

    "https://kite.trade/?status=success&request_token=zhemy8jkwdp8dkedj3jgq3uaor7od8qt"
    I am using above request token as access token in python coding.

    If access and request token is not same. let me know how to generate access token.
  • piyushgarg2323
    piyushgarg2323 edited August 2020
    @sujith - I am facing the same error. I am using the right access token. have confirmed it multiple times. I am using Pi. Kindly suggest a way out here
  • indiatechpython
    @sujit - need your guidance and recommendation for hosting server where kiteconnet API works fine. Was thinking to host my Python application at pythonanywhere but seek your guidance or recommendations if any other server
Sign In or Register to comment.