Libusb0.py cannot open a directory


#1

Hello,

I’m using a python application that access a USB device (pipsta printer) and executes a routine, it is running fine outside the container, but when it comes to the container it returns a error like this:

(File  "usr/local/lib/python2.7/dist-packages/usb/backend/libusb0.py",  line 386, in _check:
raise USBError(errmsg, ret)
USB.core.USBError: [Errno None] couldn't opendir(): No such a file or directory)

In my dockerfile I included all the python and usb relevant packages, I also moved the relevant files to /etc/udev/rules.d and restarted udev.

Thankyou in advanced


#2

Hi,

Would it be possible to show your Dockerfile so we could take a look? Perhaps a device file in /dev is not being correctly generated via udev.

Also, are you activating udev in the container? If not you should have one of the first lines run within it be udevd && udevadm trigger' which starts the udev daemon within the container, and then replays udev events which occurred in the host operating system so they are reflected in the container also.

Best, Lorenzo


#3

Of course, here is my Dockerfile:

FROM resin/rpi-raspbian:wheezy-2015-06-03
MAINTAINER Alex Frois Prado alex@shoprocket.co.uk

RUN apt-get update && apt-get install -y
build-essential
pkg-config
python
python-dev
python-pip
python-virtualenv
python-usb
git

RUN pip install Pillow
RUN pip instal pyusb
RUN pip install bitarray
RUN pip install galileo

RUN git clone https://github.com/shoprocketprinter/Pip-Application.git

COPY /Pip-Application/60-ablesystems-pyusb.rules /etc/udev/rules.d/60-ablesystems-pyusb.rules
COPY /Pip-Application/99-fitbit.rules /etc/udev/rules.d/99-fitbit.rules
CMD service udev restart

COPY /Pip-Application/usblp_blacklist.conf /etc/modprobe.d/usblp_blacklist.conf
COPY /Pip-Application/ipv6.conf /etc/modprobe.d/ipv6.conf

Workdir /Pip-Application

CMD python V1.py


#4

I notice that you have 2 CMDs in this Dockerfile - only the 2nd CMD will have any effect, that CMD service udev restart will do nothing. From the docs - ‘There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.’

You should also run udevadm trigger so the host’s udev events are rerun after udev is restarted. So overall I suggest you remove the first CMD and make the second:-

CMD service udev restart && udevadm trigger && python V1.py

Though at this point it might be worth turning this into a script, ADDing the script and having the CMD call it :smile:

Let me know if these steps resolve your issue!

Best, Lorenzo


#5

Lorenzo,
Unfortunately, I am getting the same error message :frowning:, I am using:

FROM resin/rpi-raspbian:wheezy-2015-06-03
MAINTAINER Alex Frois Prado alex@shoprocket.co.uk

RUN apt-get update && apt-get install -y
build-essential
pkg-config
python
python-dev
python-pip
python-virtualenv
python-usb
git

RUN pip install Pillow
pyusb \
bitarray \
galileo

RUN git clone https://github.com/shoprocketprinter/Resin.git

COPY /Resin/60-ablesystems-pyusb.rules /etc/udev/rules.d/60-ablesystems-pyusb.rules
COPY /Resin/99-fitbit.rules /etc/udev/rules.d/99-fitbit.rules
COPY /Resin/usblp_blacklist.conf /etc/modprobe.d/usblp_blacklist.conf
COPY /Resin/ipv6.conf /etc/modprobe.d/ipv6.conf

Workdir /Resin

Add V1.py /Resin

CMD service udev restart && udevadm trigger && python V1.py

And I get the following:

" File “/usr/local/lib/python2.7/dist-packages/usb/core.py”, line 1207, in find
return_interop._next(device_iter(k, v))
File “usr/local/lib/python2.7/dist-packages/usb/_interop.py”, line 60, in _next
retur next(iter)
File “/usr/local/lib/python2.7/dist-packages/usb/core.py”, line 1175, in device_iter
for dev in backend.enumerate_devices():
File “/usr/local/lib/python2.7/dist-packages/usb/backend/libusb0.py”, line 386, in enumerate_devices
_check(_lib.usb_find_busses())
File “/usr/local/lib/python2.7/dist-packages/usb/backend/libusb0.py”, line 380, in _check
raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] couldn’t opendir(): No such file or directory"

Outside the container the application still runs just fine.

                     Thankyou

#6

Damn, ok I’ll take a closer look at this on my side and see if I can narrow it down!

Best, Lorenzo


#7

Hey,

This is really strange, I think it is trying to look for USB file entries in an invalid location (a location which is no longer valid in recent kernels), however the libusb code clearly tries to check other locations first, specifically /dev/bus/usb so the error suggests that this directory isn’t getting populated.

Could you move the commands from the CMD into a script, and then run simply run a command to see if the directory has any contents?

E.g.:-

COPY startup.sh /Resin/startup.sh
CMD bash /Resin/startup.sh

And startup.sh:-

#!/bin/bash
service udev restart
udevadm trigger
#python V1.py
echo "/dev/bus/usb contents:-"
ls -l /dev/bus/usb
echo "done!"

I’ve experimented locally and these files do get populated, so it’s quite possible the device isn’t getting recognised for some reason.

Also try replacing service udev restart in this script with udevd &, as far as I can tell they should do the same, but it won’t hurt to experiment with that too!

Let me know the output of the above and whether udevd & helps!

Best, Lorenzo


#8

Hey, I just tried to run the sh on the container and I crossed (I tried for service udev restart and for udevd &):

   'ls: cannot access /dev/bus/usb: No such file or directory' , so I think the directory is not populated, any Idea why?


   Best,  Alex

#9

Well this would explain it :slight_smile: that’s incredibly odd, :confused: let me experiment with your FROM image some on my side.

Do you have another Raspberry Pi you could put the SD card into? It’s possible it’s a hardware issue.

Best, Lorenzo


#10

Hey,

Apologies for the delay on this, been crazy busy, I’ll take a look as soon as I get a chance!

Best, Lorenzo


#11

Thank you, just to let you know, I built the container in another device and I got the same thing.

Best, Alex


#12

Could you give me the URL to the device experiencing this? I could have a look around inside for you if you’re ok with that + get a better idea of what’s going on there. Only admins and you have access to this page so don’t worry about it being public here :slight_smile: though if would prefer it to remain private, click on the overlayed question mark in the bottom right hand corner of the page and send a message and we can discuss the issue there!

Best, Lorenzo


#14

Could you try something quickly to see if it’s related to a potential issue with the source image - replace the FROM field with FROM resin/rpi-raspbian:wheezy (i.e. not specifying the more recent build)?

Best, Lorenzo


#15

Sorry about the delay on my answer, I’ve been busy around others projects, I tried using Wheezy without specifying the version and I also tried to use Jessie both specifying the latest version and without specifying any version, I always get the same. Thank you for you engagement.


#16

One more thing to try, replace your existing udev code with the following:-

#!/bin/bash
mount -t devtmpfs none /dev
udevd &
udevadm trigger