Apr-25-2021, 01:53 PM
I need some help with the Websocket-Client (documentation). I have written a program to permanently get data from a websocket server. So far the program also works. At some point I get a "Ping/Pong timed out" error and my program closes. Until then, the program mostly ran for a few hours.
Now my question: How can I automatically restart the program? (creating an infinite Loop)
In the Code below, there is no URL given because I tried different URL“s and always the same issue.
Thanks a lot for your help or any advice.
Now my question: How can I automatically restart the program? (creating an infinite Loop)
In the Code below, there is no URL given because I tried different URL“s and always the same issue.
Thanks a lot for your help or any advice.
import websocket from datetime import datetime websocket.enableTrace(True) socketurl = "..." def on_message(wsapp, message): print(message) pass def on_open(wsapp): print(f'{str(datetime.now())} ### ONLINE ###') def on_close(wsapp): print(f'{str(datetime.now())} ### OFFLINE ###') def on_error(wsapp, error): print(f'{str(error)} ### OFFLINE ###') def on_ping(wsapp, message): print(f'{str(datetime.now())} ### Got a Ping! ###') def on_pong(wsapp, message): print(f'{str(datetime.now())} ### Send a Pong! ###') wsapp = websocket.WebSocketApp(socketurl, on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close, on_ping=on_ping, on_pong=on_pong) wsapp.run_forever(ping_interval=40, ping_timeout=30)