¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

What to do when encountering errors 502/504?


 

Hello,

There are multiple posts out there on monitoring connection status, and "raising" if 502/504.
But that is not satisfactory to my taste, the question is?how to cleanly reconnect when encountering errors 502/504?

The way I understand it, the below code similar to the linked thread, works.
The issue I see with it is that I need to re instantiate the entire API class.

Isn't there a cleaner more specific way to do this? rather than overriding the entire core thread?
For reference the class Core(EWrapper, EClient) is the API class in this case.

Thanks

def main():
core = Core()
core.connect(**TARGET)
thread = Thread(target=run, args=[core], daemon=True)
thread.start()

...

# 504 Not connected None
# 502 Couldn't connect to TWS. Confirm that "Enable ActiveX and Socket EClients"
if not thread.is_alive():
core = Core()
core.connect(**TARGET)
thread = Thread(target=run, args=[core], daemon=True)
thread.start()

...

Join [email protected] to automatically receive all group messages.