[Errno 13] Permission denied

Asked by Fred

Running Ubuntu 12.10 alpha. I get the following error.

$ python keyboard.py
Traceback (most recent call last):
  File "keyboard.py", line 25, in <module>
    main()
  File "keyboard.py", line 11, in main
    device = uinput.Device(events)
  File "/usr/lib/python2.7/dist-packages/uinput/__init__.py", line 106, in __init__
    self.__uinput_fd = _libsuinput.suinput_open()
  File "/usr/lib/python2.7/dist-packages/uinput/__init__.py", line 64, in _error_handler
    raise OSError(code, os.strerror(code))
OSError: [Errno 13] Permission denied
Exception AttributeError: "'Device' object has no attribute '_Device__uinput_fd'" in <bound method Device.__del__ of <uinput.Device object at 0x7fa0a51b7910>> ignored

Question information

Language:
English Edit question
Status:
Answered
For:
python-uinput Edit question
Assignee:
a Edit question
Last query:
Last reply:
Revision history for this message
Fred (eldmannen+launchpad) said :
#1

$ python --version
Python 2.7.3

ii python-uinput 0.8-0~tjjr1~ amd64

Revision history for this message
a (tuomasjjrasanen) said :
#2

Hi and thank you for asking this. I think this error message is quite common and hence it should be explained thoroughly.

In short, this error message tells that you don't have sufficient access rights to your system's uinput device. More specifically, you don't have write permission to /dev/uinput, that is why the error message 'OSError: [Errno 13] Permission denied'. By default in many systems, uinput is writeable only by root. Running your python-uinput application as a root would work, but it would not be a good idea in general. Fortunately, there is a better way to do it.

Python-uinput package includes a specially crafted short rule file (/etc/udev/rules.d/40-uinput.rules) which is given to udev (a process which maintains all device files). It tells udev to set /dev/uinput's group to uinput and also to allow all members of uinput group to write and read to and from /dev/uinput.

Now, you just need to create this group and add yourself (or any other user) to it:
sudo addgroup uinput
sudo adduser $USER uinput

Please note that you will need to re-login (or use newgrp) before the new group membership is valid.

Revision history for this message
Fred (eldmannen+launchpad) said :
#3

I guess I could do this.
But if I distribute my script, it would be much to ask non-technical end-users to do this.

Revision history for this message
a (tuomasjjrasanen) said :
#4

I agree that it's not something end-users of applications built on top of python-uinput should be doing. But I think I don't have any sensible means to solve it in python-uinput. In theory, I could distribute a rule which would make /dev/uinput world-writable, but in practice, it should be considered as a serious packaging bug.

I think it's application packager's / system admin's responsibility to grant proper access rights to users, not something library packager should be caring about.

In my opinion, this is something which needs to be taken care of either by post-installer script of the application using python-uinput or by a separate admin tool for the application. And of course, it depends on the nature of the application in question.

Can you help with this problem?

Provide an answer of your own, or ask Fred for more information if necessary.

To post a message you must log in.