Newly generated access token becomes invalid when taking a new position

nkmrao
Here is an issue I face from time to time.

An access token generated once in the morning should be valid for rest of the day. However, when an order for a new position is sent, the access token becomes invalid. For instance, I got the following error yesterday -
<?xml version="1.0" encoding="UTF-8"?>\nInvalidArgumentUnsupported Authorization TypeAuthorizationtoken 2lm5dfck4x41p6y6:sSQ5zmqX68biE0pa4pRkI8Ri15df6W88XS1H3PHA5X7B8WNHtoBSlaL8enn5t9KJmfZUPgulos08odzJHpJHub+0nT1BqBZ9V0Wk8e/5FsibAuQEhUH5gsEQYJ0=

The above error occurred when an order for a new position was sent. Prior to this, multiple orders to close existing positions were sent and they went through fine with the same access token. But, when an order for a new position was sent, the access token became invalid and I had to generate a new access token to continue connecting to the api.

How can this be avoided?
  • sujith
    This doesn't seem like a Kite Connect error. Kite Connect only throws json exception as mentioned here.
  • sujith
    We haven't come across any issue where in access token gets invalidated after placing an order.
  • nkmrao
    What could be the reasons why a position closing order goes through seemlessly one second and the next second a position opening order fails due to the above access token related error?
  • sujith
    You might be sending invalid access token. Or some kind of logical bug.
  • srinidhihebbar
    Faced the same issue yesterday and in the morning, I have added a try and sleep and retry after sometime.
  • srinidhihebbar

    attaching screenshot for reference
  • nkmrao
    nkmrao edited March 2023
    How is it possible that I am sending an invalid access token when the same access token fetched market data and placed orders prior to the issue? Also, the error is something the Zerodha server returned. The same order was sent twice - one was for closing position which went through, the other for opening a reverse position which failed. So, no logical bug as well.

    ChatGPT tells me this -


    I think the most likely reason is point 4. The server invalidated the access token which had to be generated again.
  • srinidhihebbar
    I don't think so that the server invalidated the Access Token, the same token worked after retry, The error is coming in whatever the first request is after login for me . It is working after retrying, there is no logic to where to use the retry as it is coming on random days, it did not happen till Monday. All my algo over AWS stopped working later found the error log .
  • srinidhihebbar
    Any updates on this? All three algos got f'ed today.
  • sathishphanikurella
    Was facing this issue since a couple of days, can someone please look into it.
    Using python client, The program will succeed if re-run for a couple of times after some time interval like a minute or two. This should have been server side issue, because I am using the same access_token.

    DataException: Unknown Content-Type (application/xml) with response: (b'<?xml version="1.0" encoding="UTF-8"?>\nInvalidArgumentUnsupported Authorization TypeAuthorizationtoken *ACTUAL TOKEN THAT WORKED AND WORKS AGAIN* *REQ ID**HOST ID*')
  • Vivek
    Which API call/method is breaking with this error?
  • srinidhihebbar
    Whatever the first API call is, it is throwing an error , getting errors in different places for different algos.
  • jits_1998
    Is this resolved? Been coming for me since thu
Sign In or Register to comment.