]> git.sven.stormbind.net Git - sven/scripts.git/commitdiff
Catch requests exceptions
authorSven Höxter <sven.hoexter@paymenttools.com>
Tue, 24 Aug 2021 07:50:19 +0000 (09:50 +0200)
committerSven Höxter <sven.hoexter@paymenttools.com>
Tue, 24 Aug 2021 07:50:19 +0000 (09:50 +0200)
home/portalmonitor.py

index 13a7b98ba55207ad7861809264eea7857cad400f..12a088e1e6970c7baaca183993bb02a6af82c609 100755 (executable)
@@ -39,22 +39,32 @@ def isDaylight(lat, lon, toleranceSeconds):
 
 def getCurrentPower(userName, password, stationId):
     with requests.Session() as s:
-        r = s.post('https://www.envertecportal.com/apiaccount/login',
-                   data={
-                       'userName': userName,
-                       'pwd': password
-                   },
-                   timeout=(10, 30))
-
-        r = s.post('https://www.envertecportal.com/ApiStations/getStationInfo',
-                   data={
-                       'stationId': stationId
-                   },
-                   timeout=(10, 60)).json()
-        power = r['Data']['Power']
-
-        r = s.post('https://www.envertecportal.com/apiAccount/Logout',
-                   timeout=(10, 30))
+        try:
+            r = s.post('https://www.envertecportal.com/apiaccount/login',
+                       data={
+                           'userName': userName,
+                           'pwd': password
+                       },
+                       timeout=(10, 30))
+        except requests.exceptions.RequestException as e:
+            raise SystemExit(e)
+
+        try:
+            r = s.post(
+                'https://www.envertecportal.com/ApiStations/getStationInfo',
+                data={
+                    'stationId': stationId
+                },
+                timeout=(10, 60)).json()
+            power = r['Data']['Power']
+        except requests.exceptions.RequestException as e:
+            raise SystemExit(e)
+
+        try:
+            r = s.post('https://www.envertecportal.com/apiAccount/Logout',
+                       timeout=(10, 30))
+        except requests.exceptions.RequestException as e:
+            raise SystemExit(e)
 
     return float(power)