From 2d1a0264a01693a9f55c9334d48765d45f1078b1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 27 Jan 2019 18:18:31 +0100 Subject: [PATCH] Reverted `e5e550bf` `decodeString` in Bridge.request In Python 3 `httplib.HTTPConnection.getresponse().read()` returns a bytes stream, not a string. Therefore commit `e5e550bf` broke the request parsing on Python 3: ``` >>> from phue import Bridge >>> b = Bridge('hue') >>> b.get_scene() Traceback (most recent call last): File "", line 1, in File "/home/blacklight/git_tree/phue/phue.py", line 1128, in get_scene return self.request('GET', '/api/' + self.username + '/scenes') File "/home/blacklight/git_tree/phue/phue.py", line 666, in request return json.loads(decodeString(response)) File "/usr/lib/python3.5/json/__init__.py", line 312, in loads s.__class__.__name__)) TypeError: the JSON object must be str, not 'bytes' ``` --- phue.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phue.py b/phue.py index 222641c..f61fd73 100755 --- a/phue.py +++ b/phue.py @@ -662,8 +662,11 @@ def request(self, mode='GET', address=None, data=None): result = connection.getresponse() response = result.read() connection.close() + if PY3K: + response = response.decode('utf-8') + logger.debug(response) - return json.loads(decodeString(response)) + return json.loads(response) def get_ip_address(self, set_result=False):