ReactorNotRestartable white connecting through API

vvrmss
please help me regarding the ReactorNotRestartable issue
import logging
from kiteconnect import KiteTicker

logging.basicConfig(level=logging.DEBUG)


# Initialise.
kws = KiteTicker(usr_api_key, usr_access_token, debug=True)
tokens = [53501959]
print("Tokens length", len(tokens))


# Callback for tick reception.
def on_ticks(ws, ticks):
print(ticks)


# Callback for successful connection.
def on_connect(ws, response):
logging.debug("on connect: {}".format(response))
ws.subscribe(tokens)
ws.set_mode(ws.MODE_FULL, tokens)


def on_close(ws, code, reason):
logging.error("closed connection on close: {} {}".format(code, reason))


def on_error(ws, code, reason):
logging.error("closed connection on error: {} {}".format(code, reason))


def on_noreconnect(ws):
logging.error("Reconnecting the websocket failed")


def on_reconnect(ws, attempt_count):
logging.debug("Reconnecting the websocket: {}".format(attempt_count))


def on_order_update(ws, data):
print("order update: ", data)


# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
kws.on_error = on_error
kws.on_noreconnect = on_noreconnect
kws.on_reconnect = on_reconnect
kws.on_order_update = on_order_update

# kws.enable_reconnect(reconnect_interval=5, reconnect_tries=50)

# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
# kws.connect(disable_ssl_verification=True)
kws.connect()

error showing
2023-06-01 11:42:11+0530 [-] Starting factory
DEBUG:kiteconnect.ticker:Start WebSocket connection.
Traceback (most recent call last):

File "C:\Users\ADMIN\Desktop\Zerodha kite connect\untitled2.py", line 63, in
kws.connect()

File "C:\Users\ADMIN\anaconda3\lib\site-packages\kiteconnect\ticker.py", line 541, in connect
reactor.run(**opts)

File "C:\Users\ADMIN\anaconda3\lib\site-packages\twisted\internet\base.py", line 1314, in run
self.startRunning(installSignalHandlers=installSignalHandlers)

File "C:\Users\ADMIN\anaconda3\lib\site-packages\twisted\internet\base.py", line 1296, in startRunning
ReactorBase.startRunning(cast(ReactorBase, self))

File "C:\Users\ADMIN\anaconda3\lib\site-packages\twisted\internet\base.py", line 840, in startRunning
raise error.ReactorNotRestartable()

ReactorNotRestartable
  • vvrmss
    I am stuck here, everything did as per doc
  • vvrmss
    vvrmss edited June 2023
    @rakeshr thanks for the suggestions, but in code everything seems good and error still there, can you please point me out to the issue
  • vvrmss
    Any update on this please
  • rakeshr
    As stated in the above FAQs, the issue is with the Anaconda environment. This thread explains in detail.
  • vvrmss
    vvrmss edited June 2023
    Yes it is Anaconda environment issue, when I try running it in python IDLE , it is working fine, thank you very much
  • vvrmss
    vvrmss edited June 2023
    can you please suggest me which environment is good for running python script for zerodha websocket, without any error
  • rakeshr
    As the above thread mentions, "If you are not concerned about acute performance computing, you may use the default python setup"
Sign In or Register to comment.