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

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 860: ordinal not in range(128) #10

Open
DunklerPhoenix opened this issue Oct 8, 2020 · 1 comment

Comments

@DunklerPhoenix
Copy link

DunklerPhoenix commented Oct 8, 2020

Heho
I have the the HDHR Expand and getting the following error from HomeAssistant.
The connection to HDHR works even with command line tools.
Is there something to fix this?

HDHomeRun EXPAND
Model: HDHR5-4DC
Firmware: 20200907

Screenshot from Home-Assistant
ouzt6LDwEH

2020-10-08 13:43:28 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.hdhomerun_tuner_1420xxxx_0 fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 278, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 469, in async_device_update
    await self.async_update()  # type: ignore
  File "/config/custom_components/hdhomerun/sensor.py", line 77, in async_update
    self._state = self.fetch_channel()
  File "/config/custom_components/hdhomerun/sensor.py", line 82, in fetch_channel
    return self.fetch_channel_raw()
  File "/config/custom_components/hdhomerun/sensor.py", line 113, in fetch_channel_raw
    streaminfo = self._adapter.get_tuner_streaminfo()
  File "/usr/local/lib/python3.8/site-packages/hdhr/adapter.py", line 259, in get_tuner_streaminfo
    unparsed = ascii_str(raw_str.value)
  File "/usr/local/lib/python3.8/site-packages/hdhr/utility.py", line 7, in ascii_str
    return str(value, encoding='ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 860: ordinal not in range(128)

EDIT: Updated issue

@DunklerPhoenix
Copy link
Author

DunklerPhoenix commented Nov 9, 2020

Okay quick and dirty fix: burnnat/hdhr@master...DunklerPhoenix:master

The Problem:
I'm living in switzerland and our channelnames have spaces and special signs like ê é

Channellist (after removing non-ascii):

1068: 849 RTL Radio F
1069: 785 hr2
1301: 701 Radio SRF 1
1302: 709 Radio SRF 2 Kul
1303: 710 Radio SRF 3
1304: 711 Radio SRF 4 New
1305: 712 Radio SRF Musik
1306: 713 Radio SRF Virus
1307: 714 Swiss Pop
1308: 715 Swiss Classic
1309: 716 Swiss Jazz
1310: 717 Radio RTR
1443: 768 BR-KLASSIK
1453: 772 SWR4 BW
1483: 787 RTL Radio
1600: 901 RSI Rete uno
1601: 902 RSI Rete due
1602: 903 RSI Rete tre
1603: 911 Rai Radio 1
1604: 912 Rai Radio 2
1605: 913 Rai Radio 3
1607: 915 Rai Radio 3 Cla
1613: 923 Radio 24 ore
1615: 909 RSI Rete uno GR
1620: 917 RDS
1621: 919 Radio Italia An
1622: 920 Virgin Radio It
1623: 921 RTL 102.5
1624: 922 Radio 101
1630: 935 Radio Maria
1631: 761 Radio Maria Sch
1632: 924 Radio Monte Car
1634: 927 Radio Studio St
1636: 929 Otto FM Italy
1638: 928 RTO
1640: 926 Radio Capital
1642: 925 DEEJAY
1644: 930 Otto FM
1700: 801 RTS la 1 re
1701: 802 RTS Espace 2
1702: 803 RTS Couleur 3
1703: 804 RTS Option Musi
1803: 884 Kral FM
1807: 887 HRT-HR1
1824: 931 Radio Sportiva
9038: 1 SRF 1 HD
9039: 2 SRF zwei HD
9040: 301 RTS 1 HD
tsid=0x000F
onid=0x0001

Raw-Channellist (before removing ascii):
raw = b'1068: 849 RTL Radio F\n1069: 785 hr2\n1301: 701 Radio SRF 1\n1302: 709 Radio SRF 2 Kul\n1303: 710 Radio SRF 3\n1304: 711 Radio SRF 4 New\n1305: 712 Radio SRF Musik\n1306: 713 Radio SRF Virus\n1307: 714 Swiss Pop\n1308: 715 Swiss Classic\n1309: 716 Swiss Jazz\n1310: 717 Radio RTR\n1443: 768 BR-KLASSIK\n1453: 772 SWR4 BW\n1483: 787 RTL Radio\n1600: 901 RSI Rete uno\n1601: 902 RSI Rete due\n1602: 903 RSI Rete tre\n1603: 911 Rai Radio 1\n1604: 912 Rai Radio 2\n1605: 913 Rai Radio 3\n1607: 915 Rai Radio 3 Cla\n1613: 923 Radio 24 ore\n1615: 909 RSI Rete uno GR\n1620: 917 RDS\n1621: 919 Radio Italia An\n1622: 920 Virgin Radio It\n1623: 921 RTL 102.5\n1624: 922 Radio 101\n1630: 935 Radio Maria\n1631: 761 Radio Maria Sch\n1632: 924 Radio Monte Car\n1634: 927 Radio Studio St\n1636: 929 Otto FM Italy\n1638: 928 RTO\n1640: 926 Radio Capital\n1642: 925 DEEJAY\n1644: 930 Otto FM\n1700: 801 RTS la 1 \xc3\xa8re\n1701: 802 RTS Espace 2\n1702: 803 RTS Couleur 3\n1703: 804 RTS Option Musi\n1803: 884 Kral FM\n1807: 887 HRT-HR1\n1824: 931 Radio Sportiva\n9038: 1 SRF 1 HD\n9039: 2 SRF zwei HD\n9040: 301 RTS 1 HD\ntsid=0x000F\nonid=0x0001\n'

Because of the Channel 1700: 801 occured the decoding error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 860: ordinal not in range(128)
To fix this I remove all non-ascii chars in function ascii_str(value)

The second problem is that the regex does not support channelnames with multiple spaces like "1302: 709 Radio SRF 2 Kul" +
This one would not be matched.
To fix this I changed the "name"-part of the regex like this:
r'^(?P<program>\d+): (?P<vchannel>\d+(?:\.\d+)?)(?: (?P<name>\S+))??(?: \((?P<flags>.+)\))?$',
https://regex101.com/r/LTXWbz/1
to
r'^(?P<program>\d+): (?P<vchannel>\d+(?:\.\d+)?)(?: (?P<name>.+))??(?: \((?P<flags>.+)\))?$',
https://regex101.com/r/NSYMIM/1
this will break the flag-support, but I didn't see any flags in any channellist, but multiple channels with () like: "305 | France 3 (Alsac"

So I think it's okay.

Thanks @Crypto90 for the help

@DunklerPhoenix DunklerPhoenix changed the title Could not get tuner vstatus (0) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 860: ordinal not in range(128) Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant