sidha / white-rose

1 stars 3 forks source link

usb.core.USBError: [Errno 13] Access denied (insufficient permissions) #2

Open figbarter opened 3 years ago

figbarter commented 3 years ago

My lsusb:

Bus 006 Device 003: ID 04f9:2028 Brother Industries, Ltd QL-570 P-touch Label Printer

My error:

$ python stickers.py printimages /home/user/HOME/Brother/Stickers/1.jpg --printer-model QL-570 --printer-url usb://0x04f9:0x2028 --sticker-count 1

Main printimages PrintImages init PrintImages.start args Namespace(command='printimages') Running PrintImages.start, args: Namespace(dry_run=False, file_extension='jpg', images=['/home/user/HOME/Brother/Stickers/1.jpg'], printer_model='QL-570', printer_url='usb://0x04f9:0x2028', sticker_count='1', sticker_size='regular') args_dict: {'images': ['/home/user/HOME/Brother/Stickers/1.jpg'], 'dry_run': False, 'printer_url': 'usb://0x04f9:0x2028', 'printer_model': 'QL-570', 'file_extension': 'jpg', 'sticker_count': '1', 'sticker_size': 'regular'} printing 1 of 1(0 remaining): /home/user/HOME/Brother/Stickers/1.jpg deprecation warning: brother_ql.devicedependent is deprecated and will be removed in a future release WARNING:brother_ql.conversion:Need to resize the image... Traceback (most recent call last): File "/home/user/stickers/venvstickers/bin/brother_ql", line 8, in sys.exit(cli()) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/click/core.py", line 1137, in call return self.main(args, kwargs) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/click/core.py", line 1062, in main rv = self.invoke(ctx) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/click/core.py", line 1668, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/click/core.py", line 763, in invoke return __callback(args, kwargs) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func return f(get_current_context(), *args, *kwargs) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/brother_ql/cli.py", line 147, in print_cmd send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/brother_ql/backends/helpers.py", line 57, in send printer = BrotherQLBackend(printer_identifier) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/brother_ql/backends/pyusb.py", line 94, in init assert self.dev.is_kernel_driver_active(0) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/usb/core.py", line 1107, in is_kernel_driver_active self._ctx.managed_open() File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/usb/core.py", line 113, in wrapper return f(self, args, kwargs) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/usb/core.py", line 131, in managed_open self.handle = self.backend.open_device(self.dev) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/usb/backend/libusb1.py", line 804, in open_device return _DeviceHandle(dev) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/usb/backend/libusb1.py", line 652, in init _check(_lib.libusb_open(self.devid, byref(self.handle))) File "/home/user/stickers/venvstickers/lib/python3.8/site-packages/usb/backend/libusb1.py", line 604, in _check raise USBError(_strerror(ret), ret, _libusb_errno[ret]) usb.core.USBError: [Errno 13] Access denied (insufficient permissions)


Based on info on Errno 13 on Stackexchange (https://stackoverflow.com/questions/50625363/usberror-errno-13-access-denied-insufficient-permissions):

I made this rule file:

/etc/udev/rules.d/01-usbBrother.rules

with this rule:

SUBSYSTEM=="usb", ATTRS{idVendor}=="04f9", MODE="0666"

using the VendorId from my lsusb output.

So I did that but still have the Errno 13.

figbarter commented 3 years ago

I've successfully printed a sticker now.

Solution seems to depend on having the abovementioned udev rules file in place, and rebooting.


After having that rules file I rebooted at first attempt I got

$ python stickers.py printimages /home/user/HOME/Brother/Stickers/1.jpg --printer-model QL-570 --printer-url usb://0x04f9:0x2028 --sticker-count 1

Main printimages PrintImages init PrintImages.start args Namespace(command='printimages') Running PrintImages.start, args: Namespace(dry_run=False, file_extension='jpg', images=['/home/user/HOME/Brother/Stickers/1.jpg'], printer_model='QL-570', printer_url='usb://0x04f9:0x2028', sticker_count='1', sticker_size='regular') args_dict: {'images': ['/home/user/HOME/Brother/Stickers/1.jpg'], 'dry_run': False, 'printer_url': 'usb://0x04f9:0x2028', 'printer_model': 'QL-570', 'file_extension': 'jpg', 'sticker_count': '1', 'sticker_size': 'regular'} printing 1 of 1(0 remaining): /home/user/HOME/Brother/Stickers/1.jpg sh: 1: brother_ql: not found

From this I learned that this must be run again after reboot:

source venvstickers/bin/activate

Successful output:

$ python stickers.py printimages /home/user/HOME/Brother/Stickers/1.jpg --printer-model QL-570 --printer-url usb://0x04f9:0x2028 --sticker-count 1

Main printimages PrintImages init PrintImages.start args Namespace(command='printimages') Running PrintImages.start, args: Namespace(dry_run=False, file_extension='jpg', images=['/home/user/HOME/Brother/Stickers/1.jpg'], printer_model='QL-570', printer_url='usb://0x04f9:0x2028', sticker_count='1', sticker_size='regular') args_dict: {'images': ['/home/user/HOME/Brother/Stickers/1.jpg'], 'dry_run': False, 'printer_url': 'usb://0x04f9:0x2028', 'printer_model': 'QL-570', 'file_extension': 'jpg', 'sticker_count': '1', 'sticker_size': 'regular'} printing 1 of 1(0 remaining): /home/user/HOME/Brother/Stickers/1.jpg deprecation warning: brother_ql.devicedependent is deprecated and will be removed in a future release WARNING:brother_ql.conversion:Need to resize the image... INFO:brother_ql.backends.helpers:Sending instructions to the printer. Total: 104024 bytes. INFO:brother_ql.backends.helpers:Printing was successful. Waiting for the next job.

figbarter commented 3 years ago

I'm reopening this issue, because maybe you should include either

  1. Add to your installation script something that writes the necessary udev rules file, or
  2. Add to your Readme an instruction to add the necessary udev rule file.

Otherwise works great, thank you!

sidha commented 3 years ago

@figbarter So you found a fix to the error? What was it? Perhaps you can show here and then I can add it? Or maybe you can submit a PR?

figbarter commented 3 years ago

@sidha

Yes, my solution is in my second post above, namely write a udev rules file and reboot.

Linuxmint 20.1 on a Thinkpad T400

Thank you for this great script.

What's a PR?

sidha commented 3 years ago

@figbarter a PR is a Pull Request where you check in new changes to this code on your your branch and then submit a Pull Request to me to confirm that it will be merged to the main codebase.

So for this you could update the README and submit a PR.