USBError: [Errno 13] Access denied (insufficient permissions)
Asked Answered
T

5

10

This problem is old as the world. There are discussions and solutions available. It all boils down to update the rules file and give permissions. So I have followed the recipe. But I still have the same problem. here are screenshots showing I follow instructions.

Versions:

Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
usb.__version__ '1.0.2'

Error:

    Traceback (most recent call last):
  File "/media/psf/Home/All-Projects-on-femto/LaserLab/Software/usb_4108.py", line 19, in <module>
    dev.set_configuration()
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 869, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 147, in managed_set_configuration
    self.managed_open()
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 120, in managed_open
    self.handle = self.backend.open_device(self.dev)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 786, in open_device
    return _DeviceHandle(dev)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 643, in __init__
    _check(_lib.libusb_open(self.devid, byref(self.handle)))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno 13] Access denied (insufficient permissions)

Rules. file (location /etc/udev/rules.d/99-usbftdi.rules)

# For FTDI FT232 & FT245 USB devices with Vendor ID = 0x0403, Product ID = 0xabc
SYSFS{idProduct}=="4108", SYSFS{idVendor}=="0683", RUN+="/sbin/modprobe -q ftdi-sio product=0x4108 vendor=0x0683"
#SYSFS{idProduct}=="2450", SYSFS{idVendor}=="0683", RUN+="/sbin/modprobe -q ftdi-sio product=0x2450 vendor=0x0683"
SYSFS{idVendor}=="0683", SYSFS{idProduct}=="4108", MODE="0666"

and strip down code:

import usb.core
import usb.util
dev = usb.core.find(idVendor=0x0683, idProduct=0x4108)
dev.reset() 

However, it doesn't give me necessary permissions. My stripped down code that still produces the error:

import usb.core
import usb.util
dev = usb.core.find(idVendor=0x0683, idProduct=0x4108)
dev.reset()

The strange thing that if I start IDLE from the terminal as superuser I get permissions (terminal: sudo idle).

Thigmotaxis answered 31/5, 2018 at 13:20 Comment(5)
What is the full path the rules file? Maybe you put it in the wrong place. Did you remember to unplug your device and plug it back in after making the udev rules file?Milurd
It is not strange at all that running a program with sudo would solve your permission problems, that's kind of the whole point of sudo and the root user.Milurd
Your rules look a little bit odd. Can you remove all of them and try this instead? SUBSYSTEM=="usb", ATTRS{idVendor}=="0683", MODE="0666"Milurd
The problem was with rules. The rule ATTRS{idVendor}=="0683", MODE="0666" works.Thigmotaxis
I solved this problem by executing the command sudo python3 app.py instead of python3 app.pyEmplacement
M
14

Your rules look a little bit odd. Can you remove all of them and try this instead?

SUBSYSTEM=="usb", ATTRS{idVendor}=="0683", MODE="0666"
Milurd answered 1/6, 2018 at 22:11 Comment(2)
ATTRS{idVendor}==0781,: command not foundEmplacement
use lower case for the value of idVendor, it's case sensitive, (1d6b instead of 1D6B)Renarenado
S
6

In case someone runs into this error again, I want to add to David Grayson's answer that you additionally have to refresh udev and unplug-and-replug the USB device. So the complete steps would be:

  1. Add line to udev file:
sudo echo 'UBSYSTEMS=="usb", ATTRS{idVendor}=="c251", ATTRS{idProduct}=="2201" GROUP="users", MODE="0666"' >> /etc/udev/rules.d/50-myusb.rules

where the vendor and product ID must go in hex and without the 0x. For example lsusb in my case produced Bus 001 Device 042: ID c251:2201 Keil Software, Inc. LASER Driver IJS and so my vendor ID is c251 and product ID is 2201.

  1. Refresh udev
sudo udevadm control --reload-rules && sudo udevadm trigger
  1. Disconnect and re-connect the USB device.

This worked for me in Ubuntu 20.04 running Python 3.8.10.

Swede answered 21/12, 2021 at 13:36 Comment(2)
Confirming disconnect and reconnect worked. Without manual udev refresh. But reboot without disconnect reconnect did NOT work. LinuxMint 19.3Resignation
There is a typo in the first command. The beginning should read as sudo echo 'SUBSYSTEMS=="usb" .... Note the first S in SUBSYSTEMS. After making this change everything worked as expected for me. You can watch for errors as udev parses things in another terminal via udevadm control --log-priority=debug && journalctl -f (you may need to run this under sudo depending on your system config). Be sure to turn this off when done (udevadm control --log-priority=notice) as it can put sensitive information in the logs.Screwdriver
C
2

user171780 post worked for me after I added an "S" and a "," the code block.. re-posting there summary with corrections, worked for me in Ubuntu 20.04.4 LTS python 3.10.4

In case someone runs into this error again, I want to add to David Grayson's answer that you additionally have to refresh udev and unplug-and-replug the USB device. So the complete steps would be:

Add line to udev file:

sudo echo 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="c251", ATTRS{idProduct}=="2201", GROUP="users", MODE="0666"' >> /etc/udev/rules.d/50-myusb.rules    

where the vendor and product ID must go in hex and without the 0x. For example lsusb in my case produced Bus 001 Device 042: ID c251:2201 Keil Software, Inc. LASER Driver IJS and so my vendor ID is c251 and product ID is 2201.

Refresh udev

    sudo udevadm control --reload-rules && sudo udevadm trigger   

Disconnect and re-connect the USB device.

Cineraria answered 15/8, 2022 at 6:7 Comment(0)
C
0

Following @joe-bob's step-by-step answer helped me configure python's hdi package. Only two things that I would like to add it:

  1. Changing the append to tee helped me due to sudo needs:
echo 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="1189", ATTRS{idProduct}=="8890", GROUP="users", MODE="0666"' | sudo tee /etc/udev/rules.d/50-myusb.rules
  1. The vendor id and product id shown in the hdi package are different than the ones shown in lusb

note: my vendor and products ids are different because my code reads data from a CH57x device

Cheerless answered 31/10, 2022 at 23:21 Comment(0)
H
-1

if you know what you're doing you can "sudo pip" install usb packages and then run python with sudo

Headliner answered 22/6, 2022 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.