Comments (9)
I was also running it an issue with _pad where is tries to concatenate bytes with a string and leads to an exception
I'm definitely not seeing this with either PyCrypto nor pyaes. We need more information.
Commit dae73ad - dumps the Python version, which may be relevant. I've seen odd byte/string behaviors with old versions of Python 3.x. Enable logging as for #1
from python-tuya.
See example error in home-assistant/core#11000 (comment)
That person appears to be using python35 on Windows. I'll do some more research into this and try to figure out if it's Python version specific or based on which crypto library is used
from python-tuya.
On my HA
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/tasks.py", line 182, in _step
result = coro.throw(exc)
File "/usr/lib/python3.6/site-packages/homeassistant/core.py", line 1031, in _event_to_service_call
yield from service_handler.func(service_call)
File "/usr/lib/python3.6/site-packages/homeassistant/components/switch/__init__.py", line 113, in async_handle_switch_service
yield from switch.async_turn_on()
File "/usr/lib/python3.6/asyncio/futures.py", line 332, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
future.result()
File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
raise self._exception
File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/switch/tuya.py", line 83, in turn_on
self._device.set_status(True, self._switchid)
File "/config/deps/lib/python3.6/site-packages/pytuya/__init__.py", line 228, in set_status
payload = self.generate_payload(command, dps_id=switch)
File "/config/deps/lib/python3.6/site-packages/pytuya/__init__.py", line 163, in generate_payload
json_payload = self.cipher.encrypt(json_payload)
File "/config/deps/lib/python3.6/site-packages/pytuya/__init__.py", line 41, in encrypt
raw = self._pad(raw)
File "/config/deps/lib/python3.6/site-packages/pytuya/__init__.py", line 71, in _pad
return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs)
TypeError: can't concat str to bytes
from python-tuya.
@nijave hopefully resolved in commit fb1c289
from python-tuya.
Turns out the reason I didn't see this was I had not ran the Python 3 and pycrypto/pycryptodome combination (only py3 and pyaes).
from python-tuya.
Just curious, any reason you're using your own padding methods instead of the ones packaged with pycrypto? See nijave@3c94c9d
from python-tuya.
I don't have that with the version of PyCrypto I have installed.
Python 2.7.13 |Anaconda 4.3.1 (32-bit)| (default, Dec 19 2016, 13:36:02) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import Crypto
>>> Crypto.__file__
'C:\\ProgramData\\Anaconda2\\lib\\site-packages\\Crypto\\__init__.pyc'
>>> Crypto.version_info
(2, 6, 1, 'final', 0)
>>> from Crypto.Util import Padding
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name Padding
Otherwise this would be much more elegant :-(
I took your branch and then merged with master into https://github.com/clach04/python-tuya/tree/3-encryption-padding - but it doesn't work for me.
Can you confirm the master branch now works for you? Then we can close this one down.
from python-tuya.
I'll go ahead and do some testing with pycrypto (the older one I think 2.6.1), pycryptodome (3.7.1 I think is what's on HA), and pyaes on both Python2 & 3 (on Windows/Cygwin). If I have time I'll do Linux, too, although I wouldn't imagine there are any issues there based on the changes. That should give us some better coverage
from python-tuya.
Resolved by pull request #9
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.