changeset 122:cb2661200dab

Retry broken connections
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 27 Feb 2021 07:44:50 +0100
parents cd36ca05c904
children b7823064b770
files examples/track_ICE/collect.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/examples/track_ICE/collect.py	Sat Jan 16 11:53:52 2021 +0100
+++ b/examples/track_ICE/collect.py	Sat Feb 27 07:44:50 2021 +0100
@@ -13,7 +13,12 @@
     print(*args, file=sys.stderr)
 
 def fetch_current(sess, api):
-    return sess.get(api).json()
+    while True:
+        try:
+            return sess.get(api).json()
+        except requests.exceptions.ConnectionError as e:
+            eprint('Retrying failed request:', e)
+            time.sleep(3)
 
 def format_server_time(servertime):
     return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(servertime/1000))