jath03 / openrgb-python

A python client for the OpenRGB SDK
GNU General Public License v3.0
112 stars 22 forks source link

OpenRGBClient() fails to get number of devices #32

Closed henryruhs closed 3 years ago

henryruhs commented 3 years ago

Hello, this issue might be similar to https://github.com/jath03/openrgb-python/issues/29 - I get this error:

OpenRGB: 0.6 openrgb-python: 0.2.9

Traceback (most recent call last):
  File "./test.py", line 8, in <module>
    client = OpenRGBClient()
  File "/home/redaxmedia/.local/lib/python3.8/site-packages/openrgb/orgb.py", line 268, in __init__
    self.comms.requestDeviceNum()
  File "/home/redaxmedia/.local/lib/python3.8/site-packages/openrgb/network.py", line 176, in requestDeviceNum
    self.read()
  File "/home/redaxmedia/.local/lib/python3.8/site-packages/openrgb/network.py", line 114, in read
    self.callback(device_id, packet_type, buff[0])
  File "/home/redaxmedia/.local/lib/python3.8/site-packages/openrgb/orgb.py", line 283, in _callback
    self.comms.requestDeviceData(x)
  File "/home/redaxmedia/.local/lib/python3.8/site-packages/openrgb/network.py", line 169, in requestDeviceData
    self.read()
  File "/home/redaxmedia/.local/lib/python3.8/site-packages/openrgb/network.py", line 133, in read
    self.callback(device_id, packet_type, utils.ControllerData.unpack(data, self._protocol_version))
  File "/home/redaxmedia/.local/lib/python3.8/site-packages/openrgb/utils.py", line 466, in unpack
    start, metadata = MetaData.unpack(data, version, start)
  File "/home/redaxmedia/.local/lib/python3.8/site-packages/openrgb/utils.py", line 413, in unpack
    start, val = parse_string(data, start)
  File "/home/redaxmedia/.local/lib/python3.8/site-packages/openrgb/utils.py", line 101, in parse_string
    val = struct.unpack(f"{size}s", data[start:start + size])[0].decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa8 in position 0: invalid start byte

You codebase contains lot of [0] that might cause nullpointer exceptions or code not to work as expected. That being said, it might be nice to raise more exceptions or fix potential unsafe code.

jath03 commented 3 years ago

What devices do you have? If it is related to #29, it would be a problem with a USB device. I did add a (slightly) better exception for parsing errors. Also, sorry this response is so late.

jath03 commented 3 years ago

Can you try using a more recent build of OpenRGB? Anything after https://gitlab.com/CalcProgrammer1/OpenRGB/-/commit/22acdd1fed976392698753b349b74233e8e319ed should work. It could fix your problem if it the same as #29

henryruhs commented 3 years ago

It works with OpenRGB 0.61 (from master) and your latest openrgb-python-0.2.10... Thanks