PYTHON WEB SOCKET ERROR : 1006 connection was closed uncleanly

babansfolio

Hello Zerodha Support Team,


From last few days While listening Tick data getting following error frequently,

Q1.
Is there any changes on Zerodha platform ? As those error intensity was very less previously.

'last_trade_time': datetime.datetime(2019, 2, 13, 11, 51, 54), 'instrument_token': 9029122, 'mode': 'full', 'sell_quantity': 334580, 'ohlc': {'high': 27273.75, 'close': 27116.6, 'open': 27200.0, 'low': 27100.0}, 'tradable': True}ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))

Q2.
Due to above error some times our data collection procedure getting out of code and execution, What is efficient way to handle it?



Tagged:
  • sujith
    It seems like your session is expired. You need to re-login to establish the connection again.
  • babansfolio
    @sujith : Is that normal that session suddenly expired? Re-login possible by generating fresh token again ? Can we change "Heart beat" value ?
  • sujith
    We don't kill websocket connection when the session expires. Your system will continue to run as is. The server will throw an error only when a user tries to connect, so in your case probably while trying to re-connect you will start noticing the error.

    One can't change heartbeat value. It is just a 1-byte ping from the server.
  • babansfolio
    @sujith : Many Thanks for your feedback.

    Is my following understanding correct based on your inputs,

    Below error is coming when our already connected system tried to reconnect with your server due to underlying connectivity issues and since our system was already connected before so
    no need to generate a new token and existing token will be enough for reconnect.

    ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))

  • sujith
    This error is because at the time of re-connection your access token seems to be expired, so you need to re-login and get a new access token.
  • babansfolio
    Hello Sujith,

    Many thanks for your feedback.

    Access token once generated it will be same and valid for whole Indian trading day, is that correct?

    What could be probable reason for expiring of access token ?

    What time at morning access token should we generate?
  • sujith
    You can check out this thread.
  • sujith
    You can generate access token post 07:35 AM
  • sagaranilganu
    @sujith @Vivek
    Note :: Am using python language for code development.
    1] Does the heart beats (of 1 byte fixed length) received in "ticks" of websocket on_tick callback, have any fixed value? (So that corresponding handler can be written!!!)
    2] If there are multiple full mode subscriptions successfully made and there is change in only 1 of the script's "LTP"; what is received in "ticks"? (My understanding :: Only the changed LTP script's full mode dictionary is received!!!)

    Your insights are most awaited!!
  • sujith
    In pykiteconnect, on_tick is not called for every heartbeat tick.
    Yes, you will receive tick of the instrument whose LTP has changed and not all the instruments.

    PS: Please don't hijack threads, this thread talks about an issue in Websocket and not about the behavior.
    This answer gets hidden and anyone else looking for the answer can't find this. Please create new thread for new queries.
Sign In or Register to comment.