Skip to content

Commit 667a520

Browse files
committed
Automatically raise exceptions on wrong http codes
1 parent c117f1a commit 667a520

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

growattServer/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def __init__(self, add_random_user_id=False, agent_identifier=None):
3737
self.agent_identifier += " - " + random_number
3838

3939
self.session = requests.Session()
40+
self.session.hooks = {
41+
'response': lambda response, *args, **kwargs: response.raise_for_status()
42+
}
4043

4144
headers = {'User-Agent': self.agent_identifier}
4245
self.session.headers.update(headers)
@@ -144,8 +147,7 @@ def plant_list(self, user_id):
144147
response = self.session.get(self.get_url('PlantListAPI.do'),
145148
params={'userId': user_id},
146149
allow_redirects=False)
147-
if response.status_code != 200:
148-
raise RuntimeError("Request failed: %s", response)
150+
149151
data = json.loads(response.content.decode('utf-8'))
150152
return data['back']
151153

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setuptools.setup(
88
name="growattServer",
9-
version="1.3.0",
9+
version="1.3.1",
1010
author="IndyKoning",
1111
author_email="[email protected]",
1212
description="A package to talk to growatt server",

0 commit comments

Comments
 (0)