blinkstick-python icon indicating copy to clipboard operation
blinkstick-python copied to clipboard

Python 3 compatibility issue

Open nltran opened this issue 9 years ago • 7 comments

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.

nltran avatar Aug 15 '15 11:08 nltran

I'm also getting this same error on windows 8 running Python 3.4.3 and blinkstick 1.1.8

DeveloperPaul123 avatar Feb 18 '16 01:02 DeveloperPaul123

I've fixed this on my fork and submitted a pull request.

atbradley avatar Aug 14 '16 03:08 atbradley

Can someone please merge this pull request?

ortix avatar Oct 24 '17 17:10 ortix

Is this fix ever going to be implemented?

jacobm001 avatar Dec 21 '17 00:12 jacobm001

Just ran up against this myself - would appreciate it being merged in, thanks.

petegibbins avatar Jan 03 '18 11:01 petegibbins

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])

lmame avatar Jul 10 '18 21:07 lmame

That helped me! Thanks!

UweZiegenhagen avatar Apr 01 '20 16:04 UweZiegenhagen