1006 - connection was closed uncleanly (peer dropped the TCP connection without previous Websocket

akhil811
Hi,

I have my access_token and api_key and using it to send mkt orders but while I try to fetch the tick data using KiteTicker API I get 1006 connection error (Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake). Could you please help understand why is this happening?

Sample code below:

from kiteconnect import KiteConnect
from kiteconnect import KiteTicker

def on_ticks(ws, ticks):
# Callback to receive ticks.
print(ticks)
print("\n")

def on_connect(ws, response):
# Callback on successful connect.
# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
ws.subscribe([81153])

# Set RELIANCE to tick in `full` mode.
ws.set_mode(ws.MODE_FULL, [81153])

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

api_key="myapikey"
access_token = "myaccesstoken""

# Initialise
kws = KiteTicker(api_key, access_token)
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close

kws.connect()
  • rakeshr
    You can go through python Websocket streaming FAQs here.
  • katemiller
    Thanks for this solution.
  • akhil811
    @rakeshr I went through the same FAQs but couldn't find my exact problem solution there. Could you point me to the exact post you're referring please? I have tried uninstalling and installing back OpenSSL, also tried a few other steps detailed there for no luck though. Hence need your some suggestions.
  • akhil811
    @rakeshr Also to be specific the FAQ does list problem and solutions for "Connection error: 1006 - connection was closed uncleanly (None)"but nothing for "Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)"
  • tahseen
    @akhil811 because you pasted code and python is an indentation based language, it is not clear whether you have made indentation mistake or not. Please ensure there is no indentation mistake

    if you think there is none, then please share exact indented code in your python file via attachment or screenshot
  • rakeshr
    Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake
    Your above code looks fine. Can you paste the complete error traceback? Disconnection reason should be highlighted in the traceback.
  • hemangjoshi37a
    @sujith can you please suggest?
Sign In or Register to comment.