Rechtevergabe in pyusb

Probleme bei der Installation?
Antworten
rfr-mailbox@gmx.de
User
Beiträge: 12
Registriert: Mittwoch 28. Oktober 2015, 12:48

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.
__deets__
User
Beiträge: 14494
Registriert: Mittwoch 14. Oktober 2015, 14:29

Gucken, ob's als root klappt? Mit dem Code hat das jedenfalls erstmal nix zu tun, der kann ja deine Rechte genausowenig eskalieren wie du das auf der Shell koenntest. Passen halt nicht, muessen passend gemacht werden.
pacifica210
User
Beiträge: 1
Registriert: Freitag 16. August 2019, 14:16

Ich weiß nicht, ob du noch eine Lösung dafür suchst. Ich hatte auch den Fehler erst und wusste nicht was ich tun soll. Dann ist mir aufgefallen, dass du den Code (genau wie ich) nicht in einer main-Methode ausführst und dass das der einzige Unterschied zum Beispiel vom pyusb tutorial ist. Wenn man alles in die main packt, kommt der Fehler nicht mehr.
Vielleicht hilft es ja jemandem weiter, der auch dieses Problem hat.
Benutzeravatar
__blackjack__
User
Beiträge: 13004
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@pacifica210: Das ist mit Sicherheit nicht die Lösung. Ob der Code in einer Funktion steht oder nicht und wie die heisst, hat beides absolut keinen Einfluss darauf wie die Rechte auf Betriebssystemebene gesetzt sind.
“Most people find the concept of programming obvious, but the doing impossible.” — Alan J. Perlis
Antworten