blinkstick-python
blinkstick-python copied to clipboard
Python 3 compatibility issue
Although the changelog states that Python 3 is supported since 1.1.5, the following error occurs while running the following code in Python 3.4.3
from blinkstick import blinkstick
b = blinkstick.find_first()
b.set_random_color()
Traceback (most recent call last):
File "C:/Users/Nam/PycharmProjects/yoloBlink/yolo.py", line 13, in <module>
b.set_random_color()
File "C:\Python34\lib\site-packages\blinkstick\blinkstick.py", line 600, in set_random_color
self.set_color(name="random")
File "C:\Python34\lib\site-packages\blinkstick\blinkstick.py", line 341, in set_color
self._usb_ctrl_transfer(0x20, 0x9, report_id, 0, control_string)
File "C:\Python34\lib\site-packages\blinkstick\blinkstick.py", line 226, in _usb_ctrl_transfer
data = (c_ubyte * len(data_or_wLength))(*[c_ubyte(ord(c)) for c in data_or_wLength])
File "C:\Python34\lib\site-packages\blinkstick\blinkstick.py", line 226, in <listcomp>
data = (c_ubyte * len(data_or_wLength))(*[c_ubyte(ord(c)) for c in data_or_wLength])
TypeError: ord() expected string of length 1, but int found
Process finished with exit code 1
Removing the ord() call in line 226 of blinkstick.py fixes the error though.
data = (c_ubyte * len(data_or_wLength))(*[c_ubyte(c) for c in data_or_wLength])
I'm using blinkstick pro, Python 3.4.3 on windows 10. I installed blinkstick 1.1.7 with pip.
I'm also getting this same error on windows 8 running Python 3.4.3 and blinkstick 1.1.8
I've fixed this on my fork and submitted a pull request.
Can someone please merge this pull request?
Is this fix ever going to be implemented?
Just ran up against this myself - would appreciate it being merged in, thanks.
I encountered the same problem, I used this to fix it: data = (c_ubyte * len(data_or_wLength))(*[c_ubyte(ord(c) if type(c) is str else c) for c in data_or_wLength])
That helped me! Thanks!