Fixed exceptions

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2021-03-12 17:23:45 +00:00
parent be0d609bda
commit 20da6220a2

View file

@ -117,9 +117,9 @@ def send_status(name, status, host, port):
# Sends status to the manager api # Sends status to the manager api
def api_send_status(name, status, api, token): def api_send_status(name, status, api, token):
try:
success = False success = False
while not success: 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"}) 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: if response.ok:
success = response.json()["success"] success = response.json()["success"]
@ -129,7 +129,7 @@ def api_send_status(name, status, api, token):
else: else:
print("Warning: Unable to send status '" + status + "' for tile '" + name + "'. Trying again in 60 seconds") print("Warning: Unable to send status '" + status + "' for tile '" + name + "'. Trying again in 60 seconds")
sleep(60) sleep(60)
except IOError: except ConnectionError:
print("Warning: Unable to send status " + status + " for tile " + name + ". Trying again in 60 seconds") print("Warning: Unable to send status " + status + " for tile " + name + ". Trying again in 60 seconds")
sleep(60) sleep(60)
@ -179,10 +179,10 @@ def api_get_job(action, api, token, none_exit=True):
print("Unable to get job. Retrying in 60 seconds...") print("Unable to get job. Retrying in 60 seconds...")
sleep(60) sleep(60)
ret = api_get_job(action, api, token, none_exit) ret = api_get_job(action, api, token, none_exit)
except IOError: except ConnectionError:
print("Unable to get job. Retrying in 60 seconds...") print("Unable to get job. Retrying in 60 seconds...")
sleep(60) sleep(60)
ret = get_job(action, host, port, none_exit) ret = api_get_job(action, api, token, none_exit)
return ret return ret
# Gets status of a tile # Gets status of a tile
@ -222,6 +222,6 @@ def api_get_status(name, api, api_token):
else: else:
print("ERROR: Unable to get status.") print("ERROR: Unable to get status.")
sys.exit(1) sys.exit(1)
except IOError: except ConnectionError:
print("ERROR: Unable to get status.") print("ERROR: Unable to get status.")
sys.exit(1) sys.exit(1)