kite ticker websocket was running fine but due to reset of internet connection, I got this exception. Exception occurred HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /portfolio/positions (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
I think it invalidates the socket ticker object.
How do I handle it in python script so to ensure continuity of the script after the internet connection is detected again? Thanks in advance
Hi Srijan, this is different error, despite using try-except in while loop. This error triggered on_close function. My on_close function is:
def on_close(ws, code, reason): logging.info('##################### KITE TICKER CONNECTION CLOSED #####################') # On connection close stop the event loop. # Reconnection will not happen after executing `ws.stop()` ws.stop()
I got the log for this error. It never got reconnected, cause the websocket got closed.
just commenting out 'ws.stop()' is enough? anything else to write for reconnection? Is this good enough?
def on_close(ws, code, reason): logging.info('##################### KITE TICKER on_close function called #####################') # On connection close stop the event loop. # Reconnection will not happen after executing `ws.stop()` # ws.stop()
https://kite.trade/forum/discussion/11748/exception-occurred-httpsconnectionpool-host-api-kite-trade-port-443-read-timed-out
You have to use try-except block to handle any exception.
But the websocket will close if there's an error.
If you want reconnection,then don't call stop method inside on_close.
https://github.com/zerodha/pykiteconnect/blob/8e36dde9fe34bb0c7c5677a4dc0fb0b1beb40787/kiteconnect/ticker.py#L342
https://kite.trade/docs/connect/v3/
Most of the common questions have already been answered.