zeth/inputs

"AttributeError: 'NoneType' object has no attribute 'get_char_device_path'"

monarrk opened this issue · 4 comments

I'm running a script for Anki Vector on a machine with Linux Mint Tessa 19.

When I don't have a gamepad plugged in, everything acts normally: it runs as far as it can without the lib and then throws an error when it can't find a gamepad. However, when the gamepad is plugged in, it immediately throws this long error message:

skye@skye-studio:~/Desktop/vector/controller$ python3 main.py
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from inputs import get_gamepad
  File "/home/skye/.local/lib/python3.6/site-packages/inputs.py", line 3652, in <module>
    devices = DeviceManager()  # pylint: disable=invalid-name
  File "/home/skye/.local/lib/python3.6/site-packages/inputs.py", line 3188, in __init__
    self._post_init()
  File "/home/skye/.local/lib/python3.6/site-packages/inputs.py", line 3200, in _post_init
    self._find_leds()
  File "/home/skye/.local/lib/python3.6/site-packages/inputs.py", line 3359, in _find_leds
    self._parse_led_path(path)
  File "/home/skye/.local/lib/python3.6/site-packages/inputs.py", line 3364, in _parse_led_path
    self.leds.append(GamepadLED(self, path, name))
  File "/home/skye/.local/lib/python3.6/site-packages/inputs.py", line 3133, in __init__
    super(GamepadLED, self).__init__(manager, path, name)
  File "/home/skye/.local/lib/python3.6/site-packages/inputs.py", line 3003, in __init__
    self._post_init()
  File "/home/skye/.local/lib/python3.6/site-packages/inputs.py", line 3137, in _post_init
    self._character_device_path = self.gamepad.get_char_device_path()
AttributeError: 'NoneType' object has no attribute 'get_char_device_path'```

I don't really know what this means and I don't know how to fix it. Any help is greatly appreciated.

I got the same (with Python 3.5) inside the docker container

Ox24 commented

I got the same error using different base images for python (arm) inside a docker container. Any tipps how to resolve it? @tomisilander

Same on Ubuntu 19 with Logitech Gamepad F310.

The problem seems to be caused by the library not being able to match the indexes of the gamepad and the LED.

The gamepad has index 1.

The LED device is /sys/class/leds/xpad0 - index 0.

I worked-around the problem by changing the post-init function like this:

    def _post_init(self):
        self._match_device()
        self._character_device_path = self.gamepad.get_char_device_path() if self.gamepad else None

Same on Linux 19.2, Python 3.6.9 with Logitech F710