Not able to unsubscribe to tokens in threaded mode

MSTrader
The following error pops up when I try to unsubscribe to all subscribed tokens in threaded=True mode.

Traceback (most recent call last):

File "D:\Anaconda\envs\pyv3916v\lib\site-packages\kiteconnect\ticker.py", line 601, in unsubscribe
for token in instrument_tokens:

RuntimeError: dictionary changed size during iteration


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\Meenakshi Sundaram\AppData\Local\Temp\ipykernel_34460\900885960.py", line 1, in
adapter.kws.unsubscribe(adapter.kws.subscribed_tokens)

File "D:\Anaconda\envs\pyv3916v\lib\site-packages\kiteconnect\ticker.py", line 609, in unsubscribe
self._close(reason="Error while unsubscribe: {}".format(str(e)))

File "D:\Anaconda\envs\pyv3916v\lib\site-packages\kiteconnect\ticker.py", line 553, in _close
self.ws.sendClose(code, reason)

File "D:\Anaconda\envs\pyv3916v\lib\site-packages\autobahn\websocket\protocol.py", line 1991, in sendClose
raise Exception("close reason without close code")

Exception: close reason without close code

Connection error: 0 - error parsing request
  • rakeshr
    Connection error: 0 - error parsing request
    You seem to be using the wrong instrument token. You can get all instrument detail from the instruments list.
  • MSTrader
    This document has all the tokens I am trying to subscribe to. Please tell me which token is causing the issue.
  • sujith
    You can check all the instrument tokens from the instruments master.
  • MSTrader
    I think this was probably happening because I did not subscribe to any instrument when i called kws.connect(), and then I was subscribing to all the instruments I wanted. The program worked as expected, and logged all the ticks despite the error.

    Now I am having a new problem, which I have posted in this thread
This discussion has been closed.