Skip to content

Commit e764e29

Browse files
committed
[Change] Provide detailed Netatmo error to ease fix of unusual problems #97
1 parent 8243fc9 commit e764e29

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lnetatmo.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,13 @@ def cameraCommand(cameraUrl, commande, parameters=None, timeout=3):
10661066
url = cameraUrl + ( commande % parameters if parameters else commande)
10671067
return postRequest("Camera", url, timeout=timeout)
10681068

1069+
def processErrorResp(resp):
1070+
try:
1071+
error_detail = json.loads(resp.fp.read().decode("utf-8"))["error"]
1072+
logger.error("Netatmo response error 403 : %s" % repr(error_detail))
1073+
except Exception as e:
1074+
logger.error("Error getting body of 403 HTTP error from Netatmo : %s" % e)
1075+
10691076
def postRequest(topic, url, params=None, timeout=10):
10701077
if PYTHON3:
10711078
req = urllib.request.Request(url)
@@ -1078,8 +1085,7 @@ def postRequest(topic, url, params=None, timeout=10):
10781085
resp = urllib.request.urlopen(req, params, timeout=timeout) if params else urllib.request.urlopen(req, timeout=timeout)
10791086
except urllib.error.HTTPError as err:
10801087
if err.code == 403:
1081-
logger.warning("Your current token scope do not allow access to %s" % topic)
1082-
raise OutOfScope("Your current token scope do not allow access to %s" % topic) from None
1088+
processErrorResp(err)
10831089
else:
10841090
logger.error("code=%s, reason=%s, body=%s" % (err.code, err.reason, err.fp.read()))
10851091
return None
@@ -1093,10 +1099,7 @@ def postRequest(topic, url, params=None, timeout=10):
10931099
try:
10941100
resp = urllib2.urlopen(req, timeout=timeout)
10951101
except urllib2.HTTPError as err:
1096-
if err.code == 403:
1097-
logger.warning("Your current token scope do not allow access to %s" % topic)
1098-
else:
1099-
logger.error("code=%s, reason=%s" % (err.code, err.reason))
1102+
logger.error("code=%s, reason=%s" % (err.code, err.reason))
11001103
return None
11011104
data = b""
11021105
for buff in iter(lambda: resp.read(65535), b''): data += buff

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='lnetatmo',
7-
version='4.2.0',
7+
version='4.2.1',
88
classifiers=[
99
'Development Status :: 5 - Production/Stable',
1010
'Intended Audience :: Developers',
@@ -17,7 +17,7 @@
1717
scripts=[],
1818
data_files=[],
1919
url='https://github.com/philippelt/netatmo-api-python',
20-
download_url='https://github.com/philippelt/netatmo-api-python/archive/v4.2.0.tar.gz',
20+
download_url='https://github.com/philippelt/netatmo-api-python/archive/v4.2.1.tar.gz',
2121
license='GPL V3',
2222
description='Simple API to access Netatmo weather station data from any python script.'
2323
)

0 commit comments

Comments
 (0)