1006 - Connection was closed uncleanly (None)


I am not able to stream all the ticks continuously. After receiving the ticks once for all the instrument tokens, I am getting the below connection error. Can you please help me resolve this?

Connection error: 1006 - connection was closed uncleanly (None)
Connection closed: 1006 - connection was closed uncleanly (None)

Please find the code below:
def on_ticks(ws, ticks):
output = pd.DataFrame()
# Callback to receive ticks.
for tick in ticks:
a={key: tick[key] for key in tick.keys() & {'timestamp', 'instrument_token', 'last_price', 'volume'}}
output = output.append(a, ignore_index=True)
output.to_csv('data2.csv', index=False)

import csv
from kiteconnect import KiteTicker
import pandas as pd

filename = "access_token.csv"
fields = []
rows = []
with open(filename, 'r') as csvfile:
read = csv.reader(csvfile)
fields = next(read)
for row in read:

access_token = rows[0][1]
api_key = rows[0][2]
api_secret = rows[0][3]
public_token = rows[0][4]


# Initialise
kws = KiteTicker(api_key, access_token)
def on_connect(ws, response):
rows = []
all_toks = []
with open(filename, 'r') as csvfile:
read = csv.reader(csvfile)
for row in read:
for i in range(1,len(rows)):

ws.set_mode(ws.MODE_FULL, all_toks)

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

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

# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.

Sign In or Register to comment.