zeth / inputs

Cross-platform Python support for keyboards, mice and gamepads
BSD 3-Clause "New" or "Revised" License
269 stars 87 forks source link

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

Open monarrk opened 5 years ago

monarrk commented 5 years ago

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.
tomisilander commented 5 years ago

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

Ox24 commented 5 years ago

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

zayfod commented 5 years ago

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
scasic commented 4 years ago

Same on Linux 19.2, Python 3.6.9 with Logitech F710