ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly

gjain
Hi All,
I am trying to run the sample code to connect websocket given in kite documentation. I am getting the following error ...


File "/usr/local/lib/python3.6/site-packages/twisted/protocols/tls.py", line 304, in dataReceived
self._tlsConnection.bio_write(bytes)
File "/usr/local/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1801, in bio_write
with _from_buffer(buf) as data:
builtins.AttributeError: __enter__

ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshae)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshke)

What could be the reason ?



  • sujith
    You can know more about it here.
  • gjain
    @sujith @rakeshr I have already gone throuh these links but the error I am getting is not listed there .

    ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshke)

    The errors mentioned there are
    ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (none)
    ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (403)
    OR
    some string related issues

    I am not able to make websocket connection with the sample code given in docs.

    Please help...
  • rakeshr
    1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
    Can you give a complete error stack trace for this?
    The above error generally occurs because of some internal exception in your code specific.
  • gjain
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /session/token HTTP/1.1" 200 None
    Unhandled error in Deferred:

    Traceback (most recent call last):
    File "/usr/local/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 3413, in _connectionMade
    self.startHandshake()
    File "/usr/local/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 3566, in startHandshake
    txaio.add_callbacks(options_d, got_options, options_failed)
    File "/usr/local/lib/python3.6/site-packages/txaio/tx.py", line 443, in add_callbacks
    future.addCallbacks(callback, errback)
    File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 330, in addCallbacks
    self._runCallbacks()
    --- ---
    File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 662, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
    File "/usr/local/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 3556, in got_options
    self._actuallyStartHandshake(request_options)
    File "/usr/local/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 3638, in _actuallyStartHandshake
    self.sendData(self.http_request_data)
    File "/usr/local/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 1336, in sendData
    self.transport.write(data)
    File "/usr/local/lib/python3.6/site-packages/twisted/protocols/tls.py", line 454, in write
    self._write(bytes)
    File "/usr/local/lib/python3.6/site-packages/twisted/protocols/tls.py", line 513, in _write
    sent = self._tlsConnection.send(toSend)
    File "/usr/local/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1644, in send
    with _from_buffer(buf) as data:
    builtins.AttributeError: __enter__

    Unhandled Error
    Traceback (most recent call last):
    File "/usr/local/lib/python3.6/site-packages/twisted/python/log.py", line 101, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
    File "/usr/local/lib/python3.6/site-packages/twisted/python/log.py", line 85, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
    File "/usr/local/lib/python3.6/site-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
    File "/usr/local/lib/python3.6/site-packages/twisted/python/context.py", line 83, in callWithContext
    return func(*args, **kw)
    --- ---
    File "/usr/local/lib/python3.6/site-packages/twisted/internet/posixbase.py", line 687, in _doReadOrWrite
    why = selectable.doRead()
    File "/usr/local/lib/python3.6/site-packages/twisted/internet/tcp.py", line 246, in doRead
    return self._dataReceived(data)
    File "/usr/local/lib/python3.6/site-packages/twisted/internet/tcp.py", line 251, in _dataReceived
    rval = self.protocol.dataReceived(data)
    File "/usr/local/lib/python3.6/site-packages/twisted/protocols/tls.py", line 304, in dataReceived
    self._tlsConnection.bio_write(bytes)
    File "/usr/local/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1801, in bio_write
    with _from_buffer(buf) as data:
    builtins.AttributeError: __enter__

    ERROR:kiteconnect.ticker: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)
  • rakeshr
    builtins.AttributeError: __enter__
    This is your internal error. Are you trying to connect to mySQL?
    This thread might help.
  • gjain
    data = kite.generate_session("**********",api_secret="***********")
    #print(data)
    kite.set_access_token(data["access_token"])
    access_token=data["access_token"]



    # Initialise
    kws = KiteTicker(api_key,access_token)

    def on_ticks(ws, ticks):
    # Callback to receive ticks.
    logging.debug("Ticks: {}".format(ticks))

    def on_connect(ws, response):
    # Callback on successful connect.
    # Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
    ws.subscribe(['738561'])
    # print ("connected")
    # Set RELIANCE to tick in `full` mode.
    ws.set_mode(ws.MODE_FULL, ['738561'])

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

    # Assign the callbacks.
    kws.on_ticks = on_ticks




    I am not using mysql . I am just trying to run sample code given in docs.
  • gjain
    Any guess ? Websocket is not getting connected ....with sample code.
  • rakeshr
    We have replied to your query here.
This discussion has been closed.