studioimaginaire / phue

A Python library for the Philips Hue system
Other
1.52k stars 267 forks source link

Commit `e5e550bf` breaks UTF-8 encoding on Python 3 #150

Closed blacklight closed 5 years ago

blacklight commented 5 years ago

Commit e5e550bf seems to address UTF-8 encoding/decoding issues on Python 2 but it actually breaks it on Python 3.

Steps to replicate:

# Python 3.5.3 (default, Sep 27 2018, 17:25:39)
>>> from phue import Bridge
>>> b = Bridge('hue')
>>> b.get_scene()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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'

get_scene works fine if I revert that commit.

I have prepared a pull request to address the issue - please consider merging ASAP as the encoding issue currently breaks any phue interaction on Python 3.

natcl commented 5 years ago

This worked in Python 3.6 for me, did you test it with a more recent version of Python ?

-- lecaude.com studioimaginaire.com

Le 27 janv. 2019 à 12:27, Fabio Manganiello notifications@github.com a écrit :

Commit e5e550bf seems to address UTF-8 encoding/decoding issues on Python 2 but it actually breaks it on Python 3.

Steps to replicate:

Python 3.5.3 (default, Sep 27 2018, 17:25:39)

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' get_scene works fine if I revert that commit.

I have prepared a pull request to address the issue - please consider merging ASAP as the encoding issue currently breaks any phue interaction on Python 3.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

natcl commented 5 years ago

Fixed with latest commit.