"[Errno 13] Access denied" when connecting to USB

5.7k views Asked by At

So I have been following these documentations so that I can print on my thermal printer through python.

I am running Ubuntu and have the pyusb module installed. The printer is a Rongta RP58, and it's idVendor and idProduct were found through the lsusb command (0fe6:811e).

Just like in the instructions, I enter:

from escpos.printer import Usb
p = Usb(0x0fe6, 0x811e)

but the error appears

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/testerdell/.local/lib/python2.7/site-packages/escpos/printer.py", line 51, in __init__
    self.open()
  File "/home/testerdell/.local/lib/python2.7/site-packages/escpos/printer.py", line 62, in open
    check_driver = self.device.is_kernel_driver_active(0)
  File "/home/testerdell/.local/lib/python2.7/site-packages/usb/core.py", line 1061, in is_kernel_driver_active
    self._ctx.managed_open()
  File "/home/testerdell/.local/lib/python2.7/site-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/home/testerdell/.local/lib/python2.7/site-packages/usb/core.py", line 120, in managed_open
    self.handle = self.backend.open_device(self.dev)
  File "/home/testerdell/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 786, in open_device
    return _DeviceHandle(dev)
  File "/home/testerdell/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 643, in __init__
    _check(_lib.libusb_open(self.devid, byref(self.handle)))
  File "/home/testerdell/.local/lib/python2.7/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)

In the documentation it suggested to create a rule that grants access, but it hasn't worked for me.

sudo nano /etc/udev/rules.d/99-escpos.rules

is the command I use to edit the file, and this is what's inside

SUBSYSTEM=="usb", ATTRS{idVendor}=="0fe6", ATTRS{idProduct}=="811e", MODE="0664", GROUP="dialout"

after changing anything in that file, I run this code:

sudo service udev restart

I am not sure how else I can give USB access to python. When using direct root access with

sudo su root

the system says "ImportError: No module named escpos.printer". I wouldn't want to enter the password for root access every single time.

Is there a problem with my udev rules, groups, mode, user permissions?

Any help is greatly appreciated! Thanks in advance :)

1

There are 1 answers

0
Marc Balmer On BEST ANSWER

Change the mode from 664 to 666 in your udev rule and it will work.