Comments (6)
@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.
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.
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.
@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.
@mike-gracia Just saw your commit. Looks also good. Maybe even better.
from python-tuya.
Resolved by #14
from python-tuya.
Related Issues (20)
- Logo Design Offer as Open Source Contribution HOT 1
- Logging is blocked when pytuya is imported HOT 1
- Web version
- BHT-6000 Thermostat (Decrypt) HOT 3
- dps status
- Vaccum Cleaner HOT 1
- ImportError: No module named 'pytuya' HOT 4
- Tuya 3.3 version support HOT 9
- Cannot use module, OutletDevice method does not exist HOT 2
- Support for curtain switch HOT 2
- Smart Life / Jinvoo request latest release installed HOT 1
- Error when changing color on the light
- Tuya App 2.8 No Longer Valid
- 7.0.4 release on PyPI HOT 2
- new switches different port HOT 3
- PIR & Door/Window Sensor Support? HOT 4
- d.status timeout with a just bought device HOT 8
- Get Device Local Key HOT 1
- 7.0.6 release HOT 2
- socket.timeout: timed out
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-tuya.