Connection error: 1006

CE7727
CE7727 edited February 2020 in Python client
Hi,

I am trying to use websocket streaming and I am getting the below error. Could not find any much in the forum. Please help.
Also, is this the most efficient way of the code layout? Basically I am trying to insert the ticks to mysql database. In a separate program I am converting to 5min candles. Will multithreding for kws.connect() help in this simple use? My main logic for signal generation is in the separate code.

Error code: 1006 reason: connection was closed uncleanly (I dropped the WebSocket TCP connection: 'float' object has no attribute 'replace')
Close code: 1006 reason: connection was closed uncleanly (I dropped the WebSocket TCP connection: 'float' object has no attribute 'replace')

My code is as follows.
def on_ticks(ws, ticks):
# Callback to receive ticks.
#print(ticks)
insert_tick(ticks)
return

def on_connect(ws, response):
# Callback on successful connect.

sub_token=get_subscribe_list()
# Subscribe to a list of instrument_tokens.
ws.subscribe(sub_token)
# Set to tick in `full` mode.
#ws.set_mode(ws.MODE_FULL, sub_token)

return

def on_close(ws, code, reason):
# On connection close stop the main loop
# Reconnection will not happen after executing `ws.stop()`
print('Close ','code:',code,'reason:',reason)
ws.stop()
return

def on_error(ws, code, reason):
print('Error ','code:',code,'reason:',reason)
return

# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
kws.on_error = on_error

# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()
Thanks
Arindam
  • sujith
    You can refer to this thread.
  • CE7727
    Thanks. So you are saying that I comment out the ws.stop() line in the on_close function? I tried doing that as well. The result was, the error kept on coming without the code stopping. If I keep ws.stop() line then the code just stops after the 1st time error. Is this an internet connectivity issue from my side? Or maybe I caught the error when the connectivity strength was low?
  • rakeshr
    @CE7727
    'float' object has no attribute 'replace'
    As per error reason,you need to type convert float to string and then use string replace inside your insert_tick method.
    Also, you shouldn't call insert _tick inside on_tick method, use multithreading instead. Check the example here.
  • CE7727
    Hi @rakeshr , Thanks for the reply. However in insert_tick function, I am inserting to a MySQL table. If error is due to float then it would have thrown DB error? I am not using any string replace in my db insert command.
  • CE7727
    I think this is happening due to insufficient internet bandwidth or weak internet connection. The same code was working fine since morning. Now that I opened few web pages to explore this error more, I suddenly got the error again. The auto connect worked and I am back streaming with no subsequent error as of now. @sujith @rakeshr
  • CE7727
    I found this https://websockets.readthedocs.io/en/stable/faq.html
    If we search for 1006 in this page I think the internet connection thing gets confirmed.
Sign In or Register to comment.