kws unsubscribe throws exception

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

Traceback (most recent call last):
File "/home/udir/envs/py36/lib/python3.6/site-packages/kiteconnect/", 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/", 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/", line 1867, in sendFrame
self.sendData(raw, sync, chopsize)
File "/home/udir/envs/py36/lib/python3.6/site-packages/autobahn/websocket/", line 1330, in sendData
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/protocols/", line 467, in write
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/protocols/", line 547, in _write
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/protocols/", line 257, in _flushSendBIO
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/", line 191, in write
FileDescriptor.write(self, bytes)
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/", line 356, in write
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/", line 443, in startWriting
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/", line 127, in addWriter
File "/home/udir/envs/py36/lib/python3.6/site-packages/twisted/internet/", 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 "", line 130, in kwsDisconnect
File "/home/udir/envs/py36/lib/python3.6/site-packages/kiteconnect/", line 600, in unsubscribe
self._close(reason="Error while unsubscribe: {}".format(str(e)))
File "/home/udir/envs/py36/lib/python3.6/site-packages/kiteconnect/", line 544, in _close, reason)
File "/home/udir/envs/py36/lib/python3.6/site-packages/autobahn/websocket/", line 2001, in sendClose
raise Exception("close reason without close code")
Exception: close reason without close code
  • rakeshr
    rakeshr edited March 2021
    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
    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.