home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.91k stars 30.14k forks source link

slimproto - 'utf-8' codec can't decode byte 0xe3 in position 16: invalid continuation byte #73611

Closed janchrillesen closed 2 years ago

janchrillesen commented 2 years ago

The problem

I am testing the slimproto integration with a Squeezebox Boom player. The player is not able to connect to the server (HA) and no device or entities gets added to the slimproto integration The homeassistant log file has a lot of entries like

2022-06-16 21:42:56 ERROR (MainThread) [aioslimproto.discovery] 'utf-8' codec can't decode byte 0xe3 in position 16: invalid continuation byte Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 202, in datagram_received data = data.decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 16: invalid continuation byte 2022-06-16 21:42:56 ERROR (MainThread) [aioslimproto.discovery] 'utf-8' codec can't decode byte 0xe3 in position 16: invalid continuation byte Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 202, in datagram_received data = data.decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 16: invalid continuation byte

What version of Home Assistant Core has the issue?

2022.6.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

slimproto

Link to integration documentation on our website

https://www.home-assistant.io/integrations/slimproto/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2022-06-16 21:42:56 ERROR (MainThread) [aioslimproto.discovery] 'utf-8' codec can't decode byte 0xe3 in position 16: invalid continuation byte
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 202, in datagram_received
    data = data.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 16: invalid continuation byte
2022-06-16 21:42:56 ERROR (MainThread) [aioslimproto.discovery] 'utf-8' codec can't decode byte 0xe3 in position 16: invalid continuation byte
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 202, in datagram_received
    data = data.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 16: invalid continuation byte

Additional information

Squeezebox Boom works fine when starting a squeezebox server on the network. All devices are in the same subnet/vlan

probot-home-assistant[bot] commented 2 years ago

slimproto documentation slimproto source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @marcelveldt, mind taking a look at this issue as it has been labeled with an integration (slimproto) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

janchrillesen commented 2 years ago

I found another Squeezebox device - this time a Duet. It generates a similar error

2022-06-20 13:33:32 ERROR (MainThread) [aioslimproto.discovery] Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 203, in datagram_received dgram = Datagram.decode(data) File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 41, in decode return ClientDiscoveryDatagram(data) File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 62, in init assert msg[0] == "d" AssertionError

Two questions

1) Should I close this issue and open a new one at https://github.com/home-assistant-libs/aioslimproto/ ? 2) Could this be an issue related to the encoding of hi-bit characters (like æ, ø and å)? It seems that Python decode() assumes everything is UTF-8, but given the age of the original Squeezebox devices I wonder if they encode using latin-1/ISO-8859-1, and we need to tell decode() about the encoding?

HomeBro commented 2 years ago

This is what I get after rebooting HA and powering on a Squeezebox Duet and try to connect it to SlimProto:

After HA Reboot:

2022-07-03 09:26:19 INFO (MainThread) [homeassistant.setup] Setting up slimproto 2022-07-03 09:26:19 INFO (MainThread) [homeassistant.setup] Setup of domain slimproto took 0.0 seconds 2022-07-03 09:26:22 INFO (MainThread) [aioslimproto.server] Starting SLIMProto server on port 3483 2022-07-03 09:26:24 INFO (MainThread) [aioslimproto.server.jsonrpc] Starting (legacy/telnet) SLIMProto CLI on port 9090 2022-07-03 09:26:27 INFO (MainThread) [aioslimproto.server.jsonrpc] Starting SLIMProto JSON RPC CLI on port 9091 2022-07-03 09:26:28 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.slimproto

Squeezebox Duet powered on:

Logger: homeassistant Source: components/slimproto/media_player.py:104 First occurred: 09.29.36 (1 occurrences) Last logged: 09.29.36

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/slimproto/media_player.py", line 63, in on_slim_event await async_add_player(player) File "/usr/src/homeassistant/homeassistant/components/slimproto/media_player.py", line 55, in async_add_player async_add_entities([SlimProtoPlayer(slimserver, player)]) File "/usr/src/homeassistant/homeassistant/components/slimproto/media_player.py", line 104, in init if "-pCP" in self.player.firmware or self.player.device_model == "SqueezeESP32": TypeError: argument of type 'NoneType' is not iterable

Logger: homeassistant Source: /usr/src/homeassistant/homeassistant/runner.py:96 First occurred: 09.29.35 (1 occurrences) Last logged: 09.29.35

Error doing job: Exception in callback SlimClient._process_stat_aude(b'\x00\x00\x0...0\x00\x00\x00') Traceback (most recent call last): File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.9/site-packages/aioslimproto/client.py", line 483, in _process_stat_aude (spdif_enable, dac_enable) = struct.unpack("2B", data[:4]) struct.error: unpack requires a buffer of 2 bytes

Logger: aioslimproto.discovery Source: /usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py:210 First occurred: 09.29.35 (1 occurrences) Last logged: 09.29.35

'utf-8' codec can't decode byte 0xc8 in position 17: unexpected end of data Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 202, in datagram_received data = data.decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 17: unexpected end of data

HomeBro commented 2 years ago

This is the Squeezebox Radio trying to connect to SlimProto:

Logger: homeassistant Source: /usr/src/homeassistant/homeassistant/runner.py:96 First occurred: 09.54.06 (7 occurrences) Last logged: 09.54.41

Error doing job: Exception in callback SlimClient._process_stat_stmt(b'\x00\x00\x0...0\x00\x00\x00') Traceback (most recent call last): File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.9/site-packages/aioslimproto/client.py", line 559, in _process_stat_stmt ) = struct.unpack("!BBBLLLLHLLLLHLLH", data) struct.error: unpack requires a buffer of 49 bytes

Logger: homeassistant Source: /usr/src/homeassistant/homeassistant/runner.py:96 First occurred: 09.54.06 (1 occurrences) Last logged: 09.54.06

Error doing job: Exception in callback SlimClient._process_stat_aude(b'\x00\x00\x0...0\x00\x00\x00') Traceback (most recent call last): File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.9/site-packages/aioslimproto/client.py", line 483, in _process_stat_aude (spdif_enable, dac_enable) = struct.unpack("2B", data[:4]) struct.error: unpack requires a buffer of 2 bytes

HomeBro commented 2 years ago

.. and the Squeezebox Boom:

Logger: aioslimproto.discovery Source: /usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py:210 First occurred: 10.02.20 (338 occurrences) Last logged: 10.09.22

'utf-8' codec can't decode byte 0x89 in position 3: invalid start byte Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 202, in datagram_received data = data.decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 3: invalid start byte

Logger: homeassistant Source: /usr/src/homeassistant/homeassistant/runner.py:96 First occurred: 10.09.13 (1 occurrences) Last logged: 10.09.13

Error doing job: Exception in callback SlimClient._process_stat_aude(b'\x04\x00\x0...0\x00\x00\x00') Traceback (most recent call last): File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.9/site-packages/aioslimproto/client.py", line 483, in _process_stat_aude (spdif_enable, dac_enable) = struct.unpack("2B", data[:4]) struct.error: unpack requires a buffer of 2 bytes

Logger: homeassistant Source: components/slimproto/media_player.py:104 First occurred: 10.09.13 (1 occurrences) Last logged: 10.09.13

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/slimproto/media_player.py", line 63, in on_slim_event await async_add_player(player) File "/usr/src/homeassistant/homeassistant/components/slimproto/media_player.py", line 55, in async_add_player async_add_entities([SlimProtoPlayer(slimserver, player)]) File "/usr/src/homeassistant/homeassistant/components/slimproto/media_player.py", line 104, in init if "-pCP" in self.player.firmware or self.player.device_model == "SqueezeESP32": TypeError: argument of type 'NoneType' is not iterable

Logger: aioslimproto.discovery Source: /usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py:210 First occurred: 10.04.26 (94 occurrences) Last logged: 10.13.30

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 203, in datagram_received dgram = Datagram.decode(data) File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 41, in decode return ClientDiscoveryDatagram(data) File "/usr/local/lib/python3.9/site-packages/aioslimproto/discovery.py", line 62, in init assert msg[0] == "d" AssertionError

janchrillesen commented 2 years ago

Hi @HomeBro - thank you for confirming my experience. It seems like another issue has been opened covering the same issue (https://github.com/home-assistant/core/issues/74265) - from what I gather from that issue, the integration is only/mainly tested with squeezelite based players and not actual Squeeze/Logitech players.