seveas / python-networkmanager

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

TypeError while assigning route-data #77

Closed lokesharo closed 3 years ago

lokesharo commented 4 years ago

I am getting the following error while assigning the IP using NetworkManager

lokesh@arora:~$ python test.py 
ERROR:dbus.connection:Unable to set arguments ({'tun': {'mode': 2}, 'ipv6': {'method': 'ignore', 'dns-priority': 100}, 'ipv4': {'method': 'manual', 'dns-priority': 100, 'gateway': '10.1.2.1', 'address-data': dbus.Array([{'address': '10.1.2.45', 'prefix': dbus.UInt32(8)}], signature=dbus.Signature('a{sv}')), 'route-data': [{'dest': '1.2.3.4', 'prefix': dbus.UInt32(16)}]}, 'connection': {'id': 'eth0', 'uuid': '6ee2cabf-472b-4340-bb34-850f0c9a277b', 'interface-name': 'eth0', 'type': 'tun', 'autoconnect': False, 'timestamp': 1576832849}},) according to signature 'a{sa{sv}}': <class 'TypeError'>: Expected a string or unicode object
Traceback (most recent call last):
  File "test.py", line 58, in <module>
    activeConnection.Connection.Update(limited_settings)
  File "<string>", line 4, in Update
  File "/home/lokesh/.local/lib/python3.6/site-packages/dbus/proxies.py", line 147, in __call__
    **keywords)
  File "/home/lokesh/.local/lib/python3.6/site-packages/dbus/connection.py", line 643, in call_blocking
    message.append(signature=signature, *args)
TypeError: Expected a string or unicode object
lokesh@arora:~$ 

Code Snippet:

addr1 = dbus.Dictionary({
    'address': '10.1.2.45',
    'prefix': dbus.UInt32(8)})

route = dbus.Dictionary({
    'dest': '1.2.3.4',
    'prefix': dbus.UInt32(16)})

s_ip4 = dbus.Dictionary({
            'address-data': dbus.Array([addr1], signature=dbus.Signature('a{sv}')),
            'route-data': dbus.Array([route], signature=dbus.Signature('a{sv}')),
            'gateway': '10.1.2.1',
            'method': 'manual'})

con = dbus.Dictionary({
    'ipv4': s_ip4})

for dev in NetworkManager.GetDevices():
    if dev.Interface == 'eth0':
        activeConnection = dev.ActiveConnection
        setting = activeConnection.Connection.GetSettings()
        final = merge_dicts(setting, con)   --> This will merge the original and new settings
        activeConnection.Connection.Update(final)

Reference: https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/dbus/update-ip4-method.py

Versions: debian package python3-networkmanager - 2.0.1-4 python-networkmanager - 2.1 python 3.6.9

kremeran commented 4 years ago

I'm running into the same issue. Any luck on finding a fix?

lokesharo commented 4 years ago

I'm running into the same issue. Any luck on finding a fix?

There is pull request opened for this issue. https://github.com/seveas/python-networkmanager/pull/60