seveas / python-networkmanager

Easy communication with NetworkManager
http://packages.python.org/python-networkmanager/
Other
166 stars 90 forks source link

KeyError: dbus.UInt32(30, variant_level=1) #68

Closed vanities closed 3 years ago

vanities commented 5 years ago

Getting this error ever since upgrading my network card. nmcli d shows me this:

wlan0            wifi      connected     dd-wrt
br-b6744aa595c6  bridge    connected     br-b6744aa595c6
veth3400933      ethernet  connected     veth3400933
veth5c9e463      ethernet  connected     veth5c9e463
veth7050827      ethernet  connected     veth7050827
veth70b4b2e      ethernet  connected     veth70b4b2e
veth75dceb0      ethernet  connected     veth75dceb0
vethd3f0d70      ethernet  connected     vethd3f0d70
p2p-dev-wlan0    wifi-p2p  disconnected  --

I think it may have something to do with p2p-dev-wlan0?

Here's the error when I try to get devices:

>>> import NetworkManager
>>> NetworkManager.NetworkManager.Devices()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 169, in get_func
    return fixups.to_python(klass, 'Get', name, data, attrib['type'])
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 550, in to_python
    val = fixups.base_to_python(val)
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 607, in base_to_python
    return [fixups.base_to_python(x) for x in val]
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 607, in <listcomp>
    return [fixups.base_to_python(x) for x in val]
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 620, in base_to_python
    return globals()[classname](val)
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 348, in __new__
    klass = device_class(obj.Get('org.freedesktop.NetworkManager.Device', 'DeviceType', dbus_interface='org.freedesktop.DBus.Properties'))
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 393, in device_class
    }[typ]
KeyError: dbus.UInt32(30, variant_level=1)
vanities commented 5 years ago
>>> NetworkManager.NetworkManager.GetDeviceByIpIface('wlan0')
>>>

>>> NetworkManager.NetworkManager.GetDeviceByIpIface('p2p-dev-wlan0')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 9, in GetDeviceByIpIface
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 550, in to_python
    val = fixups.base_to_python(val)
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 620, in base_to_python
    return globals()[classname](val)
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 348, in __new__
    klass = device_class(obj.Get('org.freedesktop.NetworkManager.Device', 'DeviceType', dbus_interface='org.freedesktop.DBus.Properties'))
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 393, in device_class
    }[typ]
KeyError: dbus.UInt32(30, variant_level=1)
cwells commented 5 years ago
Python 3.7.3 (default, May 11 2019, 00:38:04) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from NetworkManager import *
>>> NetworkManager.GetAllDevices()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 8, in GetAllDevices
  File "/home/cwells/.local/lib/python3.7/site-packages/NetworkManager.py", line 550, in to_python
    val = fixups.base_to_python(val)
  File "/home/cwells/.local/lib/python3.7/site-packages/NetworkManager.py", line 607, in base_to_python
    return [fixups.base_to_python(x) for x in val]
  File "/home/cwells/.local/lib/python3.7/site-packages/NetworkManager.py", line 607, in <listcomp>
    return [fixups.base_to_python(x) for x in val]
  File "/home/cwells/.local/lib/python3.7/site-packages/NetworkManager.py", line 620, in base_to_python
    return globals()[classname](val)
  File "/home/cwells/.local/lib/python3.7/site-packages/NetworkManager.py", line 348, in __new__
    klass = device_class(obj.Get('org.freedesktop.NetworkManager.Device', 'DeviceType', dbus_interface='org.freedesktop.DBus.Properties'))
  File "/home/cwells/.local/lib/python3.7/site-packages/NetworkManager.py", line 393, in device_class
    }[typ]
KeyError: dbus.UInt32(30, variant_level=1)
>>> 
simbelmas commented 5 years ago

I have the same error on Fedora 30

> $ nmcli device                                                            
DEVICE          TYPE      STATE         CONNECTION 
wlp2s0          wifi      connecté      ****       
p2p-dev-wlp2s0  wifi-p2p  déconnecté    --         
enp0s31f6       ethernet  indisponible  --         
docker0         bridge    non-géré      --         
lo              loopback  non-géré      --         

> $ python3                                                                 
Python 3.7.3 (default, May 11 2019, 00:38:04) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import NetworkManager
>>> NetworkManager.NetworkManager.GetDeviceByIpIface('wlp2s0')
<NetworkManager.Wireless object at 0x7f3c1fdbd2b0>
>>> NetworkManager.NetworkManager.GetDeviceByIpIface('enp0s31f6')
<NetworkManager.Wired object at 0x7f3c1fd4bfd0>
>>> NetworkManager.NetworkManager.GetDeviceByIpIface('p2p-dev-wlp2s0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 9, in GetDeviceByIpIface
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 550, in to_python
    val = fixups.base_to_python(val)
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 620, in base_to_python
    return globals()[classname](val)
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 348, in __new__
    klass = device_class(obj.Get('org.freedesktop.NetworkManager.Device', 'DeviceType', dbus_interface='org.freedesktop.DBus.Properties'))
  File "/usr/lib/python3.7/site-packages/NetworkManager.py", line 393, in device_class
    }[typ]
KeyError: dbus.UInt32(30, variant_level=1)
>>> 
cscortes commented 5 years ago

Have the same problem with this device. I think a broader solution is to not crash if you don't find something, but instead send a UNKNOWN CODE or None for anything you don't recognize. Also, I just checked on version 2.1 of python-networkmanager, the patch for WIFI_P2P is missing for Python3.7 and Python3.6.

EternityForest commented 4 years ago

I have "fixed" it with this workaround in init, by addding a default type:

def device_class(typ):
    return {
        NM_DEVICE_TYPE_ADSL: Adsl,
        NM_DEVICE_TYPE_BOND: Bond,
        NM_DEVICE_TYPE_BRIDGE: Bridge,
        NM_DEVICE_TYPE_BT: Bluetooth,
        NM_DEVICE_TYPE_ETHERNET: Wired,
        NM_DEVICE_TYPE_GENERIC: Generic,
        NM_DEVICE_TYPE_INFINIBAND: Infiniband,
        NM_DEVICE_TYPE_IP_TUNNEL: IPTunnel,
        NM_DEVICE_TYPE_MACVLAN: Macvlan,
        NM_DEVICE_TYPE_MODEM: Modem,
        NM_DEVICE_TYPE_OLPC_MESH: OlpcMesh,
        NM_DEVICE_TYPE_TEAM: Team,
        NM_DEVICE_TYPE_TUN: Tun,
        NM_DEVICE_TYPE_VETH: Veth,
        NM_DEVICE_TYPE_VLAN: Vlan,
        NM_DEVICE_TYPE_VXLAN: Vxlan,
        NM_DEVICE_TYPE_WIFI: Wireless,
        NM_DEVICE_TYPE_WIMAX: Wimax,
        NM_DEVICE_TYPE_MACSEC: MacSec,
        NM_DEVICE_TYPE_DUMMY: Dummy,
        NM_DEVICE_TYPE_PPP: PPP,
        NM_DEVICE_TYPE_OVS_INTERFACE: OvsIf,
        NM_DEVICE_TYPE_OVS_PORT: OvsPort,
        NM_DEVICE_TYPE_OVS_BRIDGE: OvsBridge
    }.get(typ,Generic)

Which lets me see a device '/virtual/device/placeholder/1', which I imagine to be the problem. I don't really understand the cause of the error, but this fix seems somewhat reasonable.

monaki commented 4 years ago

Can we merge the above PR in so that python-networkmanager can work for devices with wifi-p2p in nmcli device?

Sherry112 commented 1 year ago

I am still getting this error even though the fix was added. Someone has any idea why?

NetworkManager.NetworkManager.Version '8.6.0.12-1.22.16'

devices = NetworkManager.GetAllDevices()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 8, in GetAllDevices
  File "/usr/lib/python3.8/site-packages/NetworkManager.py", line 550, in to_python
    val = fixups.base_to_python(val)
  File "/usr/lib/python3.8/site-packages/NetworkManager.py", line 607, in base_to_python
    return [fixups.base_to_python(x) for x in val]
  File "/usr/lib/python3.8/site-packages/NetworkManager.py", line 607, in <listcomp>
    return [fixups.base_to_python(x) for x in val]
  File "/usr/lib/python3.8/site-packages/NetworkManager.py", line 620, in base_to_python
    return globals()[classname](val)
  File "/usr/lib/python3.8/site-packages/NetworkManager.py", line 348, in __new__
    klass = device_class(obj.Get('org.freedesktop.NetworkManager.Device', 'DeviceType', dbus_interface='org.freedesktop.DBus.Properties'))
  File "/usr/lib/python3.8/site-packages/NetworkManager.py", line 368, in device_class
    return {
KeyError: dbus.UInt32(30, variant_level=1)