kws unsubscribe throws exception

chaklin
'__version__': '3.9.0'
pykiteconnect
below is t6he stack trace. please help.

Traceback (most recent call last):
File "/home/udir/envs/py36/lib/python3.6/site-packages/kiteconnect/ticker.py", line 589, in unsubscribe
six.b(json.dumps({"a": self._message_unsubscribe, "v": instrument_tokens}))
File "/home/udir/envs/py36/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 2273, in sendMessage
self.sendFrame(opcode=opcode, payload=payload, sync=sync, rsv=4 if sendCompressed else 0)
File "/home/udir/envs/py36/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 1867, in sendFrame
self.sendData(raw, sync, chopsize)
File "/home/udir/envs/py36/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 1330, in sendData
self.transport.write(data)
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/protocols/tls.py", line 467, in write
self._write(bytes)
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/protocols/tls.py", line 547, in _write
self._flushSendBIO()
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/protocols/tls.py", line 257, in _flushSendBIO
self.transport.write(bytes)
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/_newtls.py", line 191, in write
FileDescriptor.write(self, bytes)
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/abstract.py", line 356, in write
self.startWriting()
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/abstract.py", line 443, in startWriting
self.reactor.addWriter(self)
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/epollreactor.py", line 127, in addWriter
EPOLLOUT, EPOLLIN)
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/epollreactor.py", line 94, in _add
self._poller.modify(fd, flags)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "myticker.py", line 130, in kwsDisconnect
kws.unsubscribe(instrument_tokens)
File "/home/udir/envs/py36/lib/python3.6/site-packages/kiteconnect/ticker.py", line 600, in unsubscribe
self._close(reason="Error while unsubscribe: {}".format(str(e)))
File "/home/udir/envs/py36/lib/python3.6/site-packages/kiteconnect/ticker.py", line 544, in _close
self.ws.sendClose(code, reason)
File "/home/udir/envs/py36/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 2001, in sendClose
raise Exception("close reason without close code")
Exception: close reason without close code
  • rakeshr
    rakeshr edited March 2021
    kws.unsubscribe(instrument_tokens)
    You need to use ws.unsubscribe(tokens) to unsubscribe required token/list of tokens.
  • chaklin
    @rakeshr i am not unsubscribing inside a callback if that is what you are referring to . but in a separate function which is being called by another py importing 'myticker'
  • rakeshr
    @chaklin
    You need to paste the WebSocket code, for us to debug this further. From the above stack trace, it looks like you are not calling unsubscribe method properly.
  • johnmalib
    When you open a file with the name “filename.ext”; you are telling the open() function that your file is in the current working directory . This is called a relative path.

    file = open('filename.ext') //relative path

    In the above code, you are not giving the full path to a file to the open() function, just its name - a relative path. The error “FileNotFoundError: [Errno 2] No such file or directory” is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path.

    file = open(r'C:\path\to\your\filename.ext') //absolute path

    In the above code, all of the information needed to locate the file is contained in the path string - absolute path.

    If the user does not pass the full path to the file (on Unix type systems this means a path that starts with a slash), the python file path is interpreted relatively to the current working directory. The current working directory usually is the directory in which you started the program. In order to make this work, the directory containing the python executable must be in the PATH, a so-called environment variable that contains directories that are automatically used for searching executables when you enter a command. In any case, if your Python script file and your data input file are not in the same directory, you always have to specify either a relative path between them or you have to use an absolute path for one of them.

Sign In or Register to comment.