From 20da6220a28f1aea1f011f48f7050a862f7bf6c3 Mon Sep 17 00:00:00 2001 From: fly Date: Fri, 12 Mar 2021 17:23:45 +0000 Subject: [PATCH] Fixed exceptions Signed-off-by: fly --- common.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/common.py b/common.py index 69fc1d6..330bc9f 100644 --- a/common.py +++ b/common.py @@ -117,9 +117,9 @@ def send_status(name, status, host, port): # Sends status to the manager api def api_send_status(name, status, api, token): - try: - success = False - while not success: + success = False + while not success: + try: response = requests.post(api, data={'auth': token, 'action': 'set', 'tile': name, 'status': status}, headers={"lAccept": "application/json", "Content-Type": "application/x-www-form-urlencoded"}) if response.ok: success = response.json()["success"] @@ -129,9 +129,9 @@ def api_send_status(name, status, api, token): else: print("Warning: Unable to send status '" + status + "' for tile '" + name + "'. Trying again in 60 seconds") sleep(60) - except IOError: - print("Warning: Unable to send status " + status + " for tile " + name + ". Trying again in 60 seconds") - sleep(60) + except ConnectionError: + print("Warning: Unable to send status " + status + " for tile " + name + ". Trying again in 60 seconds") + sleep(60) # Gets new job from manager def get_job(action, host, port, none_exit=True): @@ -179,10 +179,10 @@ def api_get_job(action, api, token, none_exit=True): print("Unable to get job. Retrying in 60 seconds...") sleep(60) ret = api_get_job(action, api, token, none_exit) - except IOError: + except ConnectionError: print("Unable to get job. Retrying in 60 seconds...") sleep(60) - ret = get_job(action, host, port, none_exit) + ret = api_get_job(action, api, token, none_exit) return ret # Gets status of a tile @@ -222,6 +222,6 @@ def api_get_status(name, api, api_token): else: print("ERROR: Unable to get status.") sys.exit(1) - except IOError: + except ConnectionError: print("ERROR: Unable to get status.") sys.exit(1)