Rechtevergabe in pyusb
Verfasst: Donnerstag 31. August 2017, 17:05
Ich schon wieder....
Fehlermeldung:
runfile('/home/rfr/.spyder2-py3/pyusb-test.py', wdir='/home/rfr/.spyder2-py3')
Stick gefunden
Traceback (most recent call last):
File "<ipython-input-5-9f08422f8540>", line 1, in <module>
runfile('/home/rfr/.spyder2-py3/pyusb-test.py', wdir='/home/rfr/.spyder2-py3')
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "/home/rfr/.spyder2-py3/pyusb-test.py", line 18, in <module>
cfg = dev.get_active_configuration()
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 875, in get_active_configuration
return self._ctx.get_active_configuration(self)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 236, in get_active_configuration
self.managed_open()
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 120, in managed_open
self.handle = self.backend.open_device(self.dev)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/backend/libusb1.py", line 786, in open_device
return _DeviceHandle(dev)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/backend/libusb1.py", line 643, in __init__
_check(_lib.libusb_open(self.devid, byref(self.handle)))
File "/home/rfr/.local/lib/python3.5/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno 13] Access denied (insufficient permissions)
----------------------------------------------------------------------------------
Quellcode
import usb.core
import usb.util
# find our device, id per lsusb suchen, meistens Quin Häng,
dev = usb.core.find(idVendor=0x1a86, idProduct=0x5512)
# was it found?
if dev is None:
raise ValueError('Device not found')
else: print ('Stick gefunden!')
# set the active configuration. With no arguments, the first
# configuration will be the active one
# dev.set_configuration()
# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
assert ep is not None
# write the data
ep.write('test')
Der fehler tritt an 'dev.set_configuration()' auf, wenn nicht auskommentiert.
Was tun?
Es existiert eine Gruppe usbuser, in der ich member bin, und die per udevregel auch <zugriff hat.
Fehlermeldung:
runfile('/home/rfr/.spyder2-py3/pyusb-test.py', wdir='/home/rfr/.spyder2-py3')
Stick gefunden
Traceback (most recent call last):
File "<ipython-input-5-9f08422f8540>", line 1, in <module>
runfile('/home/rfr/.spyder2-py3/pyusb-test.py', wdir='/home/rfr/.spyder2-py3')
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "/home/rfr/.spyder2-py3/pyusb-test.py", line 18, in <module>
cfg = dev.get_active_configuration()
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 875, in get_active_configuration
return self._ctx.get_active_configuration(self)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 236, in get_active_configuration
self.managed_open()
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/core.py", line 120, in managed_open
self.handle = self.backend.open_device(self.dev)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/backend/libusb1.py", line 786, in open_device
return _DeviceHandle(dev)
File "/home/rfr/.local/lib/python3.5/site-packages/usb/backend/libusb1.py", line 643, in __init__
_check(_lib.libusb_open(self.devid, byref(self.handle)))
File "/home/rfr/.local/lib/python3.5/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno 13] Access denied (insufficient permissions)
----------------------------------------------------------------------------------
Quellcode
import usb.core
import usb.util
# find our device, id per lsusb suchen, meistens Quin Häng,
dev = usb.core.find(idVendor=0x1a86, idProduct=0x5512)
# was it found?
if dev is None:
raise ValueError('Device not found')
else: print ('Stick gefunden!')
# set the active configuration. With no arguments, the first
# configuration will be the active one
# dev.set_configuration()
# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
assert ep is not None
# write the data
ep.write('test')
Der fehler tritt an 'dev.set_configuration()' auf, wenn nicht auskommentiert.
Was tun?
Es existiert eine Gruppe usbuser, in der ich member bin, und die per udevregel auch <zugriff hat.