Websocket 1006 error

mapreduce
mapreduce edited May 13 in Python client
I am trying to use websockets to process ticks. Here is the error I am getting:
2019-05-10 09:34:13+0530 [-] Connected to WebSocket
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
2019-05-10 09:34:13+0530 [-] subscribing to tokens: [121345, 3329, 5633, 3350017, 5436929]
2019-05-10 09:34:13+0530 [-] dropping connection to peer tcp4:13.127.19.183:443 with abort=True: I dropped the WebSocket TCP connection: close reason without close code
2019-05-10 09:34:13+0530 [-] <twisted.internet.tcp.Connector object at 0x0000017A0FE0EEB8> will retry in 2 seconds
2019-05-10 09:34:13+0530 [-] Stopping factory <kiteconnect.ticker.KiteTickerClientFactory object at 0x0000017A0F6EEC18>
Part of my code:
    
def on_ticks(self, ws, ticks):
for tick in ticks:
print('processing tick: ', tick)

def on_connect(self, ws, response):
print('Connected to WebSocket')
tokens = list()
for symbol in self.df_symbol_data.index:
tokens.append(kite_symbol_to_token(symbol))
print('subscribing to tokens: ', tokens)
ws.subscribe(tokens)
ws.set_mode(ws.MODE_QUOTE, tokens)
print('tokens: ', tokens)

def main(self):
self.initialize()
self.kite_ticker.on_ticks = self.on_ticks
self.kite_ticker.on_connect = self.on_connect
self.kite_ticker.connect(disable_ssl_verification=True)
I can confirm that access token is received and set correctly. Just before the execution of the websocket , I am also fetching historical data which is being done as it should.
Furthermore my access token was: XXXXXXX
The admins can confirm from their logs that there is no issue related to access token.

Why is this error being thrown?
Tagged:
  • zartimus
    @mapreduce Can you try with bare ticker code without any logic inside?
    If you have any blocking script inside on_ticks, please move it to separate thread.
  • mapreduce
    @zartimus

    The on_ticks function I have posted here is the exact bare one I am using as I am just testing the functionality now. Its failing.
  • mapreduce
    Can anyone help with this issue?
  • rakeshr
    @mapreduce
    We tested same code as given above by you and ticks are coming fine at our end.
    def initialize(self):
    self.kite_ticker = KiteTicker("api_key", "access_token")

    def on_ticks(self,ws, ticks):
    for tick in ticks:
    print('processing tick: ', tick)

    def on_connect(self,ws, response):
    print('Connected to WebSocket')
    #Took tokens are printed above in your ouput
    tokens= [121345, 33, 5633, 3350017, 5436929]
    print('subscribing to tokens: ', tokens)
    ws.subscribe(tokens)
    ws.set_mode(ws.MODE_QUOTE, tokens)
    print('tokens: ', tokens)

    def main(self):
    self.initialize()
    self.kite_ticker.on_ticks = self.on_ticks
    self.kite_ticker.on_connect = self.on_connect
    self.kite_ticker.connect(disable_ssl_verification=True)
  • mapreduce
    mapreduce edited May 15
    Solved the issue. I was taking the instrument tokens directly from a pandas column which has a default datatype of int64 for numbers as big as these kite tokens.
    The Kite API expects native python int datatype.
  • Vivek
    @mapreduce If you have implemented `on_error` callback then you could have logged the error. Also when in doubt always enable `debug` flag while initializing websocket to get more useful info.
  • Vivek
    on_error doesn't log this error with the debug flag on. I had tried everything already. It just mentions the error code:1006 with the reason "no reason".
    I found the issue by setting breakpoint and my eyes fell on the datatype of tokens.
    It would be great if in the next version, more helpful error messages are added to the API. Rest everything is fine.
    @mapreduce I just checked and yeah you are right. Its not sent in`on_error` callback, this is because the connection is established successfully but since its a input error on subscribe and setMode calls the errors are returned as text message. Only way to log these errors currently is to implement `on_message` callback and log only text messages (use `is_binary` flag to determine). What we will do in future version is to send JSON text error message in websocket which we can parse and call either `on_error` callback or implement a new callback.
  • mapreduce
    @Vivek

    Great. This reply is one of the reason that Kite's API leaves everyone else far behind.
  • rishiajmera
    rishiajmera edited May 21
    @Vivek @mapreduce I am still facing the same issue. I checked the data type of instrument token as well and it's native int only. Any idea what could be the issue?
Sign In or Register to comment.