Connection closed: 1006 Error. Please help with this. Code attahed.

AAAAAAAAAA
AAAAAAAAAA edited August 2021 in Python client
Full error message: Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)

I have already checked the linked webpages in regards to this error -> https://kite.trade/forum/discussion/7399/kiteconnect-ticker-connection-error-1006-connection-was-closed-uncleanly-none and it wasnt helpful.

I request someone to help me out with this. I will be extremely grateful. I will paste my code for full context.

from kiteconnect import KiteConnect
from kiteconnect import KiteTicker
import datetime as dt
import pandas as pd
import logging

access_token = open("access_token.txt", "r").read()
api_secret = open("auth.txt", "r").read().split()[1]
api_key = open("auth.txt", "r").read().split()[0]
kite = KiteConnect(api_key)
kite.set_access_token(access_token)

instruments_dump = kite.instruments("NSE")
instruments_df = pd.DataFrame(instruments_dump)



def instrument_token_lookup(symbol):

try:
symbol = symbol.upper()
return instruments_df[instruments_df["tradingsymbol"] == symbol]["instrument_token"].iloc[0]
except:
print("err in instrument token lookup function")
return -1


kws = KiteTicker(api_key, kite.access_token)

tokens = instrument_token_lookup("BHEL")

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()
  • sujith
    Are you on an office network, how long does it run before you run into this issue?
  • sujith
    Have you tried with alternate network?
  • sujith
    Like the above code, you are only printing ticks right and nothing else?
  • AAAAAAAAAA
    AAAAAAAAAA edited August 2021
    I run into this issue immediately upon running. Its an home office network, I will contact my IT team tomorrow to see if the firewall thats in place is interfering with the connection the code is trying to make - is the firewall the reason for this? Will disabling it from my IP make the thing work?

    No I have not tried using a different network.

    Yes I am only printing ticks in the on_ticks funtion and nothing else.

  • rakeshr
    s the firewall the reason for this?
    Yes, at an initial glance looks like. As you don't seem to block ticker thread, from your code.
    Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Is this the complete error traceback? if more paste complete traceback.
    You can try another network and let us know the behavior.
  • AAAAAAAAAA
    AAAAAAAAAA edited August 2021
    yes, that is the entire error traceback. It repeats after every 3 or so seconds. I am contacting my IT team regarding the firewall and will let you know whats up asap
    @sujith @rakeshr
  • AAAAAAAAAA
    So I tried using my phone data and disabling my office network, I am still getting the error @sujith @rakeshr
  • AAAAAAAAAA
    AAAAAAAAAA edited August 2021
    Clear view of the code and the error I get in the console



    The console returns this, for further context:

    runfile('/Users/apple/Desktop/AT/streaming_tick_data.py', wdir='/Users/apple/Desktop/AT')
    Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)


    (I stopped the code here)
  • AAAAAAAAAA
    @rakeshr and @sujith
    I have a solution. Its because my token function returns a Nonetype and it has to be an int.
Sign In or Register to comment.