Giter Site home page Giter Site logo

Comments (6)

clach04 avatar clach04 commented on September 25, 2024

@Exilit can you take a look at this, is this what you are seeing? What happens if you open a Python3 prompt and enter:

import json
json.loads(b'{}')
json.loads('{}')

@mike-gracia can you confirm what you are seeing on your raspbian install?

Thanks!

from python-tuya.

Exilit avatar Exilit commented on September 25, 2024

Here is what I get with my portable Python 3.4.3 installation:

>>> import json
>>> json.loads(b'{}')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<PATH_TO_PATHON>\lib\json\__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
>>> json.loads('{}')
{}

Seems really to be a bug in the json library. Python 2.6.4, Python 2.7.14 and Python 3.6.4 all accept both bytes and str.
I hope it is not related to be a portable installation. Not sure, where it is from.

from python-tuya.

mkgvb avatar mkgvb commented on September 25, 2024

3.6.4 works and 3.5.3 fails. See below

admin@DESKTOP-GGK2PSF MINGW64 ~/projects/tuya/python-tuya (master)
$ python --version
Python 3.6.4

admin@DESKTOP-GGK2PSF MINGW64 ~/projects/tuya/python-tuya (master)
$ python tests.py
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK

The output on the raspberry pi running 3.5.3 fails below.

pi@pi:~/projects/python-tuya $ python3 --version
Python 3.5.3
pi@pi:~/projects/python-tuya $ python3 tests.py
EE.
======================================================================
ERROR: test_set_status (__main__.TestXenonDevice)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 116, in test_set_status
    result = json.loads(result)
  File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

======================================================================
ERROR: test_set_timer (__main__.TestXenonDevice)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 106, in test_set_timer
    result = json.loads(result)
  File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

----------------------------------------------------------------------
Ran 3 tests in 0.012s

FAILED (errors=2)

from python-tuya.

Exilit avatar Exilit commented on September 25, 2024

@mike-gracia @clach04 I think the main question is, whether we want to work-around that or just restrict the python versions. I think targeting the raspberry pi is important, so maybe we should add something like the following:

result = json.loads(str(data, "utf-8"))

from python-tuya.

Exilit avatar Exilit commented on September 25, 2024

@mike-gracia Just saw your commit. Looks also good. Maybe even better.

from python-tuya.

clach04 avatar clach04 commented on September 25, 2024

Resolved by #14

from python-tuya.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.