access token expires frequently

ayyaz
ayyaz edited December 2017 in Python client
i am using kite for monitoring , nothing else , i get randomly access_token invalidated frequently . Please let me know how to make sure that it should session should expire once in a day .

let me know if i can automate process of access token .
  • sujith
    We do it almost every day and we haven't come across this issue. I am not sure where you are going wrong.

    As mentioned earlier, it is mandatory by the exchange that a user has to log in manually at least once a day. We don't recommend automating log in.
  • Vaga
    Even am facing same issue. The token gets invalidated every 5-10 mins. It doesn't remain logged in for the entire day. I am facing this issue since yesterday (4 Dec 17).

    kiteconnect.exceptions.TokenException: Invalid API credentials
  • sujith
    @Vaga,
    Can you let us know some more details like what did you do after generating access token?
    We couldn't reproduce this.
  • dee
    @Sujith

    I'm commenting on behalf of Vaga:

    We're doing quite normal operations such as using historical data every 15 mins, doing some processing, and then sleeping and waking up again after 15 mins. We login every day in the morning, but after a few periods, we see the invalid access token errors. This used to work quite well until last week. It has become more frequent since yesterday. Even today we ran into these token errors
  • dee
    Here's the python traceback for reference. A call to kite.historical() was made with appropriate parameters.
    ============
    user = kite.request_access_token(request_token=ACCESS_TOKEN,secret=SECRET)
    File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 269, in request_access_token
    "checksum": checksum
    File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 581, in _post
    return self._request(route, "POST", params)
    File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 668, in _request
    raise(exp(data["message"], code=r.status_code))
    kiteconnect.exceptions.TokenException: Invalid session credentials
  • sujith
    In the above code, it seems like you are sending access token to get the access token.
    Is this how you have in the code?
    You need to use a fresh request token to get the access token.
  • dee
    ok, that was a wrong copy paste, Here's the actual traceback:
    =========
    Traceback (most recent call last):
    File "", line 1, in
    File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 522, in historical
    "continuous": 1 if continuous else 0})
    File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 577, in _get
    return self._request(route, "GET", params)
    File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 668, in _request
    raise(exp(data["message"], code=r.status_code))
    kiteconnect.exceptions.TokenException: Invalid API credentials
  • sujith
    Can you private message the api_key you are using?
    I will check and get back to you.
  • sunny
    Hi Sujith,

    I am facing the same issue from last couple of days. I do normal data reading. not executing any trade...still it expires within few mins.
  • sujith
    Hi @sunny,
    It seems like your historical data subscription is expired.
  • vikasnitk85
    Hi Sujith,

    I have got my historical data activated yestreday only, and I am also facing the same issues, it gives an error that "Invalid API Credentials", however when I re-run it, my access token doesn't change. Please not that I have not logged out, just restarted the python session. Could you please help me out.
  • sujith
    Hi,
    A request token is valid for only a couple of minutes and it can be used only once. Don't request for access token for every run. Once you receive an access token, use the same for subsequent runs.

    An access token is valid for one whole day. Unless you log out. If your previous access token is still active then the system will give you back the same access token which is fine.

    After you subscribe to historical data, you need to re-login to use historical data API.
Sign In or Register to comment.