rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.91k stars 557 forks source link

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 #566

Open michaelroussel2494 opened 3 years ago

michaelroussel2494 commented 3 years ago

Sometime device show as unavaible in homeassistant:

Home assistant core-2021.7.4 LocalTuya 3.2.2

Logger: custom_components.localtuya.common Source: custom_components/localtuya/pytuya/init.py:196 Integration: LocalTuya integration (documentation, issues) First occurred: 18 septembre 2021, 23:38:17 (208 occurrences) Last logged: 18 septembre 2021, 23:56:35

error message:

[bfa...q1q] Connect to 172.16.20.5 failed Traceback (most recent call last): File "/config/custom_components/localtuya/common.py", line 149, in _make_connection status = await self._interface.status() File "/config/custom_components/localtuya/pytuya/init.py", line 472, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 457, in exchange payload = self._decode_payload(msg.payload) File "/config/custom_components/localtuya/pytuya/init.py", line 544, in _decode_payload payload = self.cipher.decrypt(payload, False) File "/config/custom_components/localtuya/pytuya/init.py", line 196, in decrypt return self._unpad(decryptor.update(enc) + decryptor.finalize()).decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 75: invalid continuation byte

It's possible to have a fix ?

Thanks in advance

CloCkWeRX commented 2 years ago

I experience this too locally. Unclear what the specific output from the specific device is that is completely invalid. Present on 3.5.0+ / master.

CloCkWeRX commented 2 years ago

Seems like pytuya as an upstream repo is unmaintained; unclear if the failure to decode problems are upstream (https://github.com/clach04/python-tuya) or introduced in the fork.

https://github.com/clach04/python-tuya/blob/master/pytuya/__init__.py#L76 vs https://github.com/rospogrigio/localtuya/blob/master/custom_components/localtuya/pytuya/__init__.py#L197

Potentially, we should review the history of changes to our fork and cut over to upstream or an active fork of upstream.

IE: https://github.com/jasonacox/tinytuya/blob/master/tinytuya/__init__.py#L273