From 3b7418a33eb0a1d86c8b9646395c5b0597bcb615 Mon Sep 17 00:00:00 2001 From: Konstantinos Kamaropoulos Date: Wed, 8 Jan 2020 10:13:32 +0200 Subject: [PATCH] feat: Add try/expect block for request to REST API, in case something goes wrong --- main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 50a2db3..6c8e302 100644 --- a/main.py +++ b/main.py @@ -26,9 +26,12 @@ def dataHandler(data): jsonData = json.dumps(dataToSend) url = 'http://192.168.100.11:3000/logs' - req = requests.post(url, json = dataToSend) - print(req.text) + try: + req = requests.post(url, json = dataToSend) + print(req.text) + except Exception as e: + print(e) # 2. Listen for data while True: