Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message: The length of the provided data is not a multiple of the block length #1452

Open
2 tasks done
lennon101 opened this issue Jul 7, 2023 · 9 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@lennon101
Copy link

-->

The problem

Reopening issue number #78 which was closed in 2020. I have on the latest version (v5.2.1) and experiencing the exact same probelm. My home-assistant log has a repeating error (seems to be stuck in a loop) with the following contents:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/lib/python3.10/asyncio/selector_events.py", line 1035, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
    data = data.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position 0: invalid continuation byte
2023-07-07 14:10:02.176 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
  File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
    data = decrypt_udp(data)
  File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
    return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
  File "/usr/lib/python3.10/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 185, in finalize
    data = self._ctx.finalize()
  File "/usr/lib/python3.10/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 222, in finalize
    raise ValueError(
ValueError: The length of the provided data is not a multiple of the block length.

During handling of the above exception, another exception occurred:

Environment

  • Localtuya version: v5.2.1
  • Home Assistant Core version: Home Assistant 2023.7.1
  • Does the device work using the Home Assistant Tuya Cloud component ?
  • Was the device working with earlier versions of localtuya ?
@lennon101 lennon101 added the bug Something isn't working label Jul 7, 2023
@lennon101
Copy link
Author

Just updating the errror message to include everything in its entirety. It's very possible this is linked to only some devices. The issue is, I can't seem to be able to see in the log which device is sending the data that can't be decoded. Any help with this?

2023-07-09 13:07:10.955 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
  File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
    data = decrypt_udp(data)
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
    return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
                                              ^^^^^^^^^^^^^^^^^^^^
  File "/lsiopy/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 186, in finalize
    data = self._ctx.finalize()
           ^^^^^^^^^^^^^^^^^^^^
  File "/lsiopy/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 222, in finalize
    raise ValueError(
ValueError: The length of the provided data is not a multiple of the block length.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 1169, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
    data = data.decode()
           ^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 2: invalid start byte

@r-estermann
Copy link

r-estermann commented Jul 13, 2023

I think i have the same issue.
I have an tuya LED Wifi controller i want to connect with localtuya and got "no devices detected"
In debug log I have same errors like above:

`2023-07-13 17:21:26.574 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
data = decrypt_udp(data)
^^^^^^^^^^^^^^^^^
File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 186, in finalize
data = self._ctx.finalize()
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 222, in finalize
raise ValueError(
ValueError: The length of the provided data is not a multiple of the block length.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1169, in _read_ready
self._protocol.datagram_received(data, addr)
File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
data = data.decode()
^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 0: invalid continuation byte`

any ideas?
thx

@paris-ci
Copy link

I have the same issue, but with a slightly different callback

homeassistant  | 2023-09-24T20:15:10.224641226Z 2023-09-24 22:15:10.223 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
homeassistant  | 2023-09-24T20:15:10.224684415Z Traceback (most recent call last):
homeassistant  | 2023-09-24T20:15:10.224701616Z   File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
homeassistant  | 2023-09-24T20:15:10.224711216Z     data = decrypt_udp(data)
homeassistant  | 2023-09-24T20:15:10.224719499Z            ^^^^^^^^^^^^^^^^^
homeassistant  | 2023-09-24T20:15:10.224727561Z   File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
homeassistant  | 2023-09-24T20:15:10.224757487Z     return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
homeassistant  | 2023-09-24T20:15:10.224766868Z                                               ^^^^^^^^^^^^^^^^^^^^
homeassistant  | 2023-09-24T20:15:10.224774219Z   File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 186, in finalize
homeassistant  | 2023-09-24T20:15:10.224781901Z     data = self._ctx.finalize()
homeassistant  | 2023-09-24T20:15:10.224790268Z            ^^^^^^^^^^^^^^^^^^^^
homeassistant  | 2023-09-24T20:15:10.224798384Z   File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 222, in finalize
homeassistant  | 2023-09-24T20:15:10.224807164Z     raise ValueError(
homeassistant  | 2023-09-24T20:15:10.224814635Z ValueError: The length of the provided data is not a multiple of the block length.
homeassistant  | 2023-09-24T20:15:10.224822231Z
homeassistant  | 2023-09-24T20:15:10.224829401Z During handling of the above exception, another exception occurred:
homeassistant  | 2023-09-24T20:15:10.224837978Z
homeassistant  | 2023-09-24T20:15:10.224846053Z Traceback (most recent call last):
homeassistant  | 2023-09-24T20:15:10.224853971Z   File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
homeassistant  | 2023-09-24T20:15:10.224862520Z     self._context.run(self._callback, *self._args)
homeassistant  | 2023-09-24T20:15:10.224870306Z   File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1163, in _read_ready
homeassistant  | 2023-09-24T20:15:10.224878876Z     self._protocol.datagram_received(data, addr)
homeassistant  | 2023-09-24T20:15:10.224885376Z   File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
homeassistant  | 2023-09-24T20:15:10.224890793Z     data = data.decode()
homeassistant  | 2023-09-24T20:15:10.224895824Z            ^^^^^^^^^^^^^
homeassistant  | 2023-09-24T20:15:10.224902953Z UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: invalid continuation byte

@paris-ci
Copy link

paris-ci commented Nov 5, 2023

So I investigated a bit, other smartlife things seems to be detected correctly, but these switches are the one causing the problem :

https://www.amazon.fr/Programmable-Compatible-Consommation-ventilateur-climatiseur/dp/B0C5MX9F38/

"EIGHTREE Prise Connectée WiFi 5GHz, Prise Alexa Programmable, Compatible avec Alexa/Google Home/Smart Life APP, Suivi de Consommation, Contrôler le ventilateur/climatiseur, 16A 3680W, Type F, 4PCS"

@sharkwsk
Copy link

Anyone able to fix this issue, I get the same error messages and some devices are not discovered in localtuya

@paris-ci
Copy link

Use this instead https://github.com/xZetsubou/hass-localtuya

@sharkwsk
Copy link

Thanks heaps @paris-ci - this new integration works perfectly

@sowmyagowri
Copy link

Thanks a ton @paris-ci !!!!

@paris-ci
Copy link

:D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants