muammar / mkchromecast

Cast macOS and Linux Audio/Video to your Google Cast and Sonos Devices
http://mkchromecast.com
Other
2.23k stars 140 forks source link

Encode available device names to UTF-8 #463

Closed SamuelMereau closed 6 months ago

SamuelMereau commented 6 months ago

Resolves this error when attempting to run bin/mkchromecast.

Traceback (most recent call last):
  File "/home/<username>/mkchromecast/bin/mkchromecast", line 288, in <module>
    CastProcess(mkcc).run()
  File "/home/<username>/mkchromecast/bin/mkchromecast", line 68, in run
    self.start_audiocast()
  File "/home/<username>/mkchromecast/bin/mkchromecast", line 97, in start_audiocast
    self.cc.initialize_cast()
  File "/home/<username>/mkchromecast/bin/../mkchromecast/cast.py", line 114, in initialize_cast
    print_available_devices(self.available_devices)
  File "/home/<username>/mkchromecast/bin/../mkchromecast/cast.py", line 62, in print_available_devices
    print(device)
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2019' in position 13: ordinal not in range(256)
Killed

For context, I am using the library on a Raspberry Pi 4 with the following system specifiations

<username>@raspberrypi:~ $ cat /proc/version
Linux version 6.1.21-v8+ (dom@buildbot) (aarch64-linux-gnu-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023

This solution works for me. However, I am not a Python developer, so please review this if there would be a better way to resolve this long term.

xsdg commented 6 months ago

Hi, Samuel. Could you share the output of these diagnostic commands? (I'm also including the output on my machine, just to have context in the bug)

$python --version
bash: python: command not found

$python3 --version
Python 3.11.9

$env | grep LANG
LANG=en_US.UTF-8

Lastly, if you're willing to share the name of your Chromecast, that would be really helpful (but I understand that it can be personal, so np if you don't want to share it)

I would like to be able to reproduce the issue you ran into, because I'm not entirely sure how it would manifest (I have a Chromecast with an emoji in the name and that works fine locally)

SamuelMereau commented 6 months ago

Hi @xsdg, more than happy to share, and no worries happy to provide the name of the troublesome device.

<username>@raspberrypi:~/mkchromecast $ python --version
Python 3.9.2
<username>@raspberrypi:~/mkchromecast $ python3 --version
Python 3.9.2
<username>@raspberrypi:~/mkchromecast $ env | grep LANG
LANGUAGE=en_AU
LANG=en_AU

The name of the device is Sam’s Room clock