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

device.detach_kernel_driver(0) - ERROR Could not detach kernel driver: [Errno 13] Access denied (insufficient permissions) #83

Open
jonnymoshiri opened this issue Aug 16, 2022 · 2 comments

Comments

@jonnymoshiri
Copy link

Hello,

I have an issue running the following code, in my cloned github repo.

`from blinkstick import blinkstick

bstick = blinkstick.find_first()

#Set the color red on the 12th LED of R channel
bstick.set_color(channel=0, index=12, name="red")`

Specifically it fails in the call at find_first call. here is the full traceback.

Traceback (most recent call last):
File "/Users/jmoshiri/Documents/Repos/blinkstick-python/blinkstick/blinkstick.py", line 821, in open_device
self.device.detach_kernel_driver(0)
File "/Users/jmoshiri/Documents/Repos/blinkstick-python/venv/lib/python3.9/site-packages/usb/core.py", line 1075, in detach_kernel_driver
self._ctx.backend.detach_kernel_driver(
File "/Users/jmoshiri/Documents/Repos/blinkstick-python/venv/lib/python3.9/site-packages/usb/backend/libusb1.py", line 902, in detach_kernel_driver
_check(self.lib.libusb_detach_kernel_driver(dev_handle.handle, intf))
File "/Users/jmoshiri/Documents/Repos/blinkstick-python/venv/lib/python3.9/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/jmoshiri/Documents/Repos/blinkstick-python/trial.py", line 4, in
bstick = blinkstick.find_first()
File "/Users/jmoshiri/Documents/Repos/blinkstick-python/blinkstick/blinkstick.py", line 1581, in find_first
return BlinkStick(device=d)
File "/Users/jmoshiri/Documents/Repos/blinkstick-python/blinkstick/blinkstick.py", line 215, in init
self.open_device(device)
File "/Users/jmoshiri/Documents/Repos/blinkstick-python/blinkstick/blinkstick.py", line 823, in open_device
raise BlinkStickException("Could not detach kernel driver: %s" % str(e))
blinkstick.blinkstick.BlinkStickException: Could not detach kernel driver: [Errno 13] Access denied (insufficient permissions)

I have given all the correct permissions in the set up for Blinkstick, and also given read write priveleges for all dependencies (usblib and pyusb) . My machine is running Mac OSx Big Sur and I am using Python 3.9.13. The only other way I was thinking to blinkstick via sudo priveleges either from the command line or from the IDE (pycharm in my case).

I got stumped at the command line priveleges in the set up because i do not have a directory udev in /etc for mac OS Big Sur

echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\"20a0\", ATTR{idProduct}==\"41e5\", MODE:=\"0666\"" | sudo tee /etc/udev/rules.d/85-blinkstick.rules

Any help is appreciated.

@dmingram66
Copy link

I've been looking at this on a Mac running Monterey on the arm64 architecture. Apple have a built in Kernel driver which does not need to be detached. I have commented out the call to self.open_device(device) on line 217 and the library still functions correctly. I'm trying to work out how to check if we are running on MacOS before suggesting a change to the library.

I do not advise running anything under sudo privileges, in any case the problem lies in an interaction between libusb and the operating system.

@dmingram66
Copy link

Here is a zip file containing a version which doesn't call open_device() if the platform is "macOS-12.6"

AppleSilicon.zip

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