From 2a67fd8e3e13b88c84dd9279eed4a56da57e8dd6 Mon Sep 17 00:00:00 2001 From: Mathieu B Date: Sun, 1 Aug 2021 23:15:28 +0200 Subject: [PATCH] catch conencter error on request --- jarvis/utils/server_utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/jarvis/utils/server_utils.py b/jarvis/utils/server_utils.py index 0cb763d..fa78378 100644 --- a/jarvis/utils/server_utils.py +++ b/jarvis/utils/server_utils.py @@ -35,11 +35,14 @@ def send_sentence_to_server(sentence): headers['Client-Port'] = str(config_utils.get_in_config('PORT')) # headers["Authorization"] = config_utils.get_in_config("API_KEY") - response = requests.post(url_service, - headers=headers, - json={'sentence': sentence}) + try: + response = requests.post(url_service, + headers=headers, + json={'sentence': sentence}) - print(bytes.decode(response.content)) + print(bytes.decode(response.content)) + except ConnectionError: + print("Error connecting to the server (server was probably shutdown during request)...") def get_server_port():