connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close

ravhui
Can someone help me to fix this connection issue.
Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)

P.S : I'm using python
  • ravhui
    @sujith can you look into this
  • vithalpatil
    Hi @sujith,

    Same issue here not getting ticks after 6pm using official python library. i running it under jupyter notebook on AWS EC2 server.
  • girish400
    The ticker stops working after a while! Can you please check ?

    2018-05-29 11:29:25,037 - kiteconnect.ticker - DEBUG - last ping was 2.5006039142608643 seconds back.
    2018-05-29 11:29:25,294 - kiteconnect.ticker - DEBUG - last pong was 2.4975969791412354 seconds back.
    2018-05-29 11:29:25,295 - kiteconnect.ticker - DEBUG - pong => b''
    2018-05-29 11:29:27,539 - kiteconnect.ticker - DEBUG - ping =>
    2018-05-29 11:29:27,539 - kiteconnect.ticker - DEBUG - last ping was 2.500602960586548 seconds back.
    2018-05-29 11:29:27,796 - kiteconnect.ticker - DEBUG - last pong was 2.5016067028045654 seconds back.
    2018-05-29 11:29:27,797 - kiteconnect.ticker - DEBUG - pong => b''
    2018-05-29 11:29:30,040 - kiteconnect.ticker - DEBUG - ping =>
    2018-05-29 11:29:30,040 - kiteconnect.ticker - DEBUG - last ping was 2.5006039142608643 seconds back.
    2018-05-29 11:29:30,298 - kiteconnect.ticker - DEBUG - last pong was 2.5006046295166016 seconds back.
    2018-05-29 11:29:30,298 - kiteconnect.ticker - DEBUG - pong => b''
    2018-05-29 11:29:32,542 - kiteconnect.ticker - DEBUG - ping =>
    2018-05-29 11:29:32,542 - kiteconnect.ticker - DEBUG - last ping was 2.500603675842285 seconds back.
    2018-05-29 11:29:32,800 - kiteconnect.ticker - DEBUG - last pong was 2.5016064643859863 seconds back.
    2018-05-29 11:29:32,800 - kiteconnect.ticker - DEBUG - pong => b''
    2018-05-29 11:29:35,044 - kiteconnect.ticker - DEBUG - ping =>
    2018-05-29 11:29:35,044 - kiteconnect.ticker - DEBUG - last ping was 2.500603675842285 seconds back.
    2018-05-29 11:29:35,300 - kiteconnect.ticker - DEBUG - last pong was 2.5006043910980225 seconds back.
    2018-05-29 11:29:35,301 - kiteconnect.ticker - DEBUG - pong => b''
    2018-05-29 11:29:37,545 - kiteconnect.ticker - DEBUG - ping =>
    2018-05-29 11:29:37,545 - kiteconnect.ticker - DEBUG - last ping was 2.5006043910980225 seconds back.
    2018-05-29 11:29:37,807 - kiteconnect.ticker - DEBUG - last pong was 2.5056190490722656 seconds back.
    2018-05-29 11:29:37,808 - kiteconnect.ticker - DEBUG - pong => b''
    2018-05-29 11:29:40,047 - kiteconnect.ticker - DEBUG - ping =>
    2018-05-29 11:29:40,047 - kiteconnect.ticker - DEBUG - last ping was 2.500603675842285 seconds back.
    2018-05-29 11:29:40,157 - kiteconnect.ticker - ERROR - Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
    2018-05-29 11:29:40,158 - root - ERROR - closed connection on error: 1006 connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
    2018-05-29 11:29:40,158 - kiteconnect.ticker - ERROR - Connection closed: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
    2018-05-29 11:29:40,159 - root - ERROR - closed connection on close: 1006 connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
    2018-05-29 11:29:40+0530 [KiteTickerClientProtocol (TLSMemoryBIOProtocol),client] will retry in 2 seconds
    2018-05-29 11:29:40+0530 [-] Stopping factory
    2018-05-29 11:29:40+0530 [-] Main loop terminated.
  • kaushalmalkan
    Hi,

    I am facing the same issue while streaming for tick data

    My code was working perfectly till yesterday. Getting this issue since today morning.

    Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
  • kaushalmalkan
    kaushalmalkan edited July 2020
    Hi, @rakeshr I went through it but unfortunately couldn't find my solution.

    My streaming code:

    from kiteconnect import KiteConnect
    from kiteconnect import KiteTicker
    import pandas as pd
    import os

    cwd = os.chdir("I:\Algo")


    #generate trading session
    access_token = open("access_token.txt",'r').read()
    key_secret = open("api_key.txt",'r').read().split()
    kite = KiteConnect(api_key=key_secret[0])
    kite.set_access_token(access_token)

    #get dump of all NSE instruments
    instrument_dump = kite.instruments("NSE")
    instrument_df = pd.DataFrame(instrument_dump)

    def tokenLookup(instrument_df,symbol_list):
    """Looks up instrument token for a given script from instrument dump"""
    token_list = []
    for symbol in symbol_list:
    token_list.append(int(instrument_df[instrument_df.tradingsymbol==symbol].instrument_token.values[0]))
    return token_list

    #####################update ticker list######################################
    tickers = ["INFY", "ACC", "ICICIBANK", "HDFCBANK"]
    #############################################################################

    #create KiteTicker object
    kws = KiteTicker(key_secret[0],kite.access_token)
    tokens = tokenLookup(instrument_df,tickers)

    def on_ticks(ws,ticks):
    print(ticks)

    def on_connect(ws,response):
    ws.subscribe(tokens)
    ws.set_mode(ws.MODE_LTP,[tokens])


    kws.on_ticks=on_ticks
    kws.on_connect=on_connect
    kws.connect()
    I can fetch OHLC as well, the problem is only with streaming tick data.

    Everything loads perfectly just while executing kws.connect() I get the error of:

    Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)

    I even tried regenerating a new API secret but that was of no use as well.

    Please assist.
  • rakeshr
    @kaushalmalkan
    ws.set_mode(ws.MODE_LTP,[tokens])
    You are sending instrument token as Nested list(list of list). As you are already returning instrument list in tokenLookup function. So, you can just pass same list.
    ws.set_mode(ws.MODE_LTP,tokens)
  • Appytraders
    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)

    I am facing the same issue. Can someone please help with solution
  • rakeshr
    You can go through Python client Websocket FAQs. Connection closing solution is explained there.
Sign In or Register to comment.