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)