websocket connect issue

gjain
Not able to connect websocket ...

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)


I am trying to run sample code given in docs . Kite APIs are working fine on the same environment ... Here I give the sample code which I am trying to run ...
---------------------------------------

import logging
from kiteconnect import KiteTicker

logging.basicConfig(level=logging.DEBUG)

# Initialise
kws = KiteTicker("************", "************")

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, 5633])

# 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
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.
kws.connect()
~

Please help me on this ...






  • rakeshr
    File "/usr/local/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1644, in send
    with _from_buffer(buf) as data:
    builtins.AttributeError: __enter__
    Looks like an Open SSL issue. Can you try uninstalling and installing pyOpenSSL? Follow below step:
    pip uninstall pyOpenSSL
    pip install pyOpenSSL
  • gjain
    @rakeshr Thanks!! It worked
This discussion has been closed.