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 #15

Open
kovaszab opened this issue Aug 2, 2021 · 3 comments
Open

UnicodeDecodeError #15

kovaszab opened this issue Aug 2, 2021 · 3 comments

Comments

@kovaszab
Copy link

kovaszab commented Aug 2, 2021

When trying to access client devices with client.devices() I got an error message:

Traceback (most recent call last):
  File "/home/arc/PycharmProjects/plasma_rgb/main.py", line 11, in <module>
    for device in client.devices():
  File "/home/arc/PycharmProjects/plasma_rgb/venv/lib/python3.9/site-packages/openrgb/OpenRGB.py", line 60, in devices
    yield self.controller_data(device_id)
  File "/home/arc/PycharmProjects/plasma_rgb/venv/lib/python3.9/site-packages/openrgb/OpenRGB.py", line 48, in controller_data
    return ORGBDevice(msg[1], device_id, owner=self)
  File "/home/arc/PycharmProjects/plasma_rgb/venv/lib/python3.9/site-packages/openrgb/ORGBDevice.py", line 215, in __init__
    self.serial = blob.string()
  File "/home/arc/PycharmProjects/plasma_rgb/venv/lib/python3.9/site-packages/openrgb/binreader.py", line 58, in string
    unpacked = self._unpack(
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc8 in position 1: ordinal not in range(128)

I'm using OpenRGB version 0.6 and OpenRGB-PyClient version 0.1.1 with Python 3.9.6

@bahorn
Copy link
Owner

bahorn commented Aug 6, 2021

So I setup the versions you used, and it doesn't seem to reproduce on my end, at least with my hardware. (Linux, AppImage build of 0.6 and the library installed from pip, Python 3.9.5)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc8 in position 1: ordinal not in range(128)

Couple ideas for why this would happen:

  • Odd device name? 0xc8 is the code for È apparently, or at least as a prefix for a few unicode characters, so do you have something with that in it? Seems the code only allows ascii characters in the device name which is probably a wrong assumption. Changing the .decode('ascii') to .decode('utf-8') should fix that.
  • My parser is broken. Seems to have held up well so far, so tbh it would surprise me. A test case would be useful, so if it not the first I'd love a testcase to include as a unit test. Patching the library to just save the values that ORGBDevice() gets passed should be enough.
  • Could be some api changes since when I wrote a lot of the code, but 0.6 was pretty similar iirc. Only expect breaking changes that I need to address in 0.7

@kovaszab
Copy link
Author

kovaszab commented Aug 9, 2021

I removed .decode('ascii') from binreader.py at line 60, and it works.

            unpacked = self._unpack(
                '{}s'.format(total_len)
-->        )[0]
            if unpacked[-1] == '\x00':
                return unpacked[:-1]
            return unpacked

@kovaszab
Copy link
Author

kovaszab commented Aug 9, 2021

My devices are:

b'Holtek USB Gaming Mouse\x00' - ORGBDeviceType.MOUSE
b'Holtek USB Gaming Mouse\x00' - ORGBDeviceType.MOUSE
b'Holtek USB Gaming Mouse\x00' - ORGBDeviceType.MOUSE
b'Holtek USB Gaming Mouse\x00' - ORGBDeviceType.MOUSE
b'Holtek USB Gaming Mouse\x00' - ORGBDeviceType.MOUSE
b'Holtek USB Gaming Mouse\x00' - ORGBDeviceType.MOUSE
b'B550 GAMING X V2\x00' - ORGBDeviceType.MOTHERBOARD
b'B550 GAMING X V2\x00' - ORGBDeviceType.MOTHERBOARD
b'AMD Wraith Prism\x00' - ORGBDeviceType.COOLER

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

2 participants