Connection Error: 1006

deadlock
I am using KiteTicker in threaded mode and I get the 1006 error within few seconds of starting the program. I uninstalled and installed pyOpenSSL as suggested in another thread. I need MODE_FULL only and also need to receive all ticks. Please help as I am not an experienced python coder.

Below is the terminal log:
INFO:root:Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
INFO:root:Connection closed: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)

ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (SSL error: sslv3 alert bad record mac (in ))

Entire code of main.py (for reference):
from kiteconnect import KiteTicker
import logging

def onconnect(ws, response):
tokens = [13299458]
ws.subscribe(tokens)
ws.set_mode(ws.MODE_FULL, tokens)

def onticks(ws, ticks):
logging.info("Ticks: {}".format(ticks))

logging.basicConfig(level=logging.DEBUG)
kt = KiteTicker(api_key='***', access_token='***')

# Callback when current connection is closed.
def onclose(ws, code, reason):
logging.info("Connection closed: {code} - {reason}".format(code=code, reason=reason))

# Callback when connection closed with error.
def onerror(ws, code, reason):
logging.info("Connection error: {code} - {reason}".format(code=code, reason=reason))

# Callback when reconnect is on progress
def onreconnect(ws, attempts_count):
logging.info("Reconnecting: {}".format(attempts_count))

# Callback when all reconnect failed (exhausted max retries)
def onnoreconnect(ws):
logging.info("Reconnect failed.")

# Assign the callbacks.
kt.on_ticks = onticks
kt.on_connect = onconnect
kt.on_close = onclose
kt.on_error = onerror
kt.on_reconnect = onreconnect
kt.on_noreconnect = onnoreconnect

kt.connect(threaded=True)

tokens = [13299458]
while True:
if kt.is_connected():
kt.set_mode(kt.MODE_FULL, tokens)

Version Details:
1. Kite Connect API version: 4.1.0
2. pyOpenSSL: 22.1.0
3. Python version: 3.10.7
4. Windows version: Windows 10



  • rakeshr
    peer dropped the TCP connection without previous WebSocket closing handshake
    SSL error: sslv3 alert bad record mac (in )
    Looks like your other thread created is closing the main connection. Maybe you can try without a multi-threading setup.
  • deadlock
    @rakeshr:
    Just for the record, that did not help. And, that is okay. It is not easy to determine the issue in remote and offline environment. BTW, I mentioned in my post that I need multi-threading.
  • rakeshr
    Yes, SSL problems are quite hard to find, you will need to do this on your end. Sometimes it's related to SSL lib, sometimes related to requests from abused IPs, multi-thread locking, etc. Maybe debug all possible scenarios one by one. This thread might be of help.
    Multi-threading for WebSocket stream is perfectly fine for multiple users including me. So, it seems to be your local issue.
  • deadlock
    @rakeshhr:
    You have unilaterally decided for a user this thread is linked to the current thread because you are in a hurry to close the contentious one. The last comments made by you here are also incorrect. The current thread was opened on Oct 7 and the issue was resolved by me on the same day. I started receiving EOD ticks of Oct 7 after that on Oct 8, Oct 9 and Oct 10 (pre-market hours) also. Only on Oct 10 around 9:00 AM, I started encountering the kiteticker.connect() connection issue, which is when I opened a new thread completely unrelated to the current one.

    The issue in this thread is still open. Reopen this thread until that issue is actually resolved.
Sign In or Register to comment.