seveas / python-networkmanager Goto Github PK
View Code? Open in Web Editor NEWEasy communication with NetworkManager
Home Page: http://packages.python.org/python-networkmanager/
License: Other
Easy communication with NetworkManager
Home Page: http://packages.python.org/python-networkmanager/
License: Other
python-networkmanager =====================⚠️ This project is no longer maintained.⚠️ If you are looking for an alternative, please try https://github.com/python-sdbus/python-sdbus-networkmanager If python-sdbus-networkmanager does not fit your needs, and you wish to revive this project, please contact me.
How can I set the location of a ca certification and pasword-flags when creating a new wpa-enterprise connection?
Based on your example:
WPA_connection = {
'802-11-wireless': {'mode': 'infrastructure',
'security': '802-11-wireless-security',
'ssid': 'n-m-example-connection'},
'802-11-wireless-security': {'auth-alg': 'open', 'key-mgmt': 'wpa-eap'},
'802-1x': {'eap': ['peap'],
'ca-cert': cert_location,
'identity': eid,
'pasword-flags': '1',
'phase2-auth': 'mschapv2'},
'connection': {'id': 'nm-example-connection',
'type': '802-11-wireless',
'uuid': str(uuid.uuid4())},
'ipv4': {'method': 'auto'},
'ipv6': {'method': 'auto'}
}
NetworkManager.Settings.AddConnection(WPA_connection)
but that gives me a dbus exception:
dbus.exceptions.DBusException: org.freedesktop.NetworkManager.Settings.Connection.InvalidProperty: 802-1x.ca-cert: can't set property of type 'GBytes' from value of type 's'
*EDIT: Also, how do you set the mac-address?
While other signals work fine (PropertiesChanged
and DeviceAdded
among others) I was not able to get a notification for DeviceRemoved
. My sample code is a modified listener.py
example:
import dbus.mainloop.glib
from gi.repository import GObject, GLib
import NetworkManager
import time
def out(msg):
print("%s %s" % (time.strftime('%H:%M:%S'), msg))
def statechange(nm, interface, signal, state):
out("State changed to %s" % NetworkManager.const('STATE', state))
def adddevice(nm, interface, signal, device_path):
try:
out("Device %s added" % device_path.IpInterface)
except NetworkManager.ObjectVanished:
# Sometimes this signal is sent for *removed* devices. Ignore.
pass
def removedevice(*args, **kw):
out("removedevice: {} {}".format(args, kw))
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
NetworkManager.NetworkManager.OnStateChanged(statechange)
NetworkManager.NetworkManager.OnDeviceAdded(adddevice)
NetworkManager.NetworkManager.OnDeviceRemoved(removedevice)
loop = GObject.MainLoop()
loop.run()
if __name__ == '__main__':
main()
Hello,
I just tested this on Ubuntu lucid (custom install based on XBMClive). I cant get it to work,
Network manager is working. The only thing I can think of is if have to test it on a standard ubuntu desktop?
import NetworkManager
ERROR:dbus.proxies:Introspect error on :1.51:/org/freedesktop/NetworkManager: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Message did not receive a reply (timeout by message bus)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.6/dist-packages/NetworkManager.py", line 95, in
NetworkManager = NetworkManager()
File "/usr/local/lib/python2.6/dist-packages/NetworkManager.py", line 18, in init
dbus_interface='org.freedesktop.DBus.Properties')
File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 68, in call
return self._proxy_method(_args, *_keywords)
File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 140, in call
**keywords)
File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 620, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name :1.51 was not provided by any .service files
I encountered some access points with SSID byte sequences not decodable as utf-8. Here are two examples
Here NetworkManager bails out like so
File "/usr/local/lib/python3.5/dist-packages/NetworkManager.py", line 81, in get_func
return self.postprocess(name, self.unwrap(data))
File "/usr/local/lib/python3.5/dist-packages/NetworkManager.py", line 299, in postprocess
return fixups.ssid_to_python(val)
File "/usr/local/lib/python3.5/dist-packages/NetworkManager.py", line 425, in ssid_to_python
return bytes("",'ascii').join(ssid).decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 2: invalid start byte
It's fairly easy to catch, but harder to get raw bytes to do something more meaningful with. Perhaps there could be another function on the AccessPoint
class for example, get_raw_ssidthat returns a
bytes` object.
Whats your thoughts on this @seveas ?
notify2 is not working although it is installed correctly. It's showing no module named dbus error
When I tried installing dbus using pip install dbus-python, I got this error
Collecting dbus-python
Using cached https://files.pythonhosted.org/packages/3f/e7/4edb582d1ffd5ac3c84188deea32e960b5c8c0fe1da56ce70224f85ce542/dbus-python-1.2.8.tar.gz
Building wheels for collected packages: dbus-python
Running setup.py bdist_wheel for dbus-python ... error
Complete output from command /home/swapneil/anaconda3/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-install-b_jnkttm/dbus-python/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/pip-wheel-rnr9pyhm --python-tag cp36:
running bdist_wheel
running build
creating /tmp/pip-install-b_jnkttm/dbus-python/build
creating /tmp/pip-install-b_jnkttm/dbus-python/build/temp.linux-x86_64-3.6
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define EXTENSIONS... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking whether UID '1000' is supported by ustar format... yes
checking whether GID '1000' is supported by ustar format... yes
checking how to create a ustar tar archive... gnutar
checking dependency style of gcc... gcc3
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for native Windows host... no
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @file support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for inline... inline
checking for gawk... (cached) mawk
checking for python... /home/swapneil/anaconda3/bin/python
checking for a version of Python >= '2.1.0'... yes
checking for a version of Python >= '2.7'... yes
checking for the distutils Python package... yes
checking for Python include path... -I/home/swapneil/anaconda3/include/python3.6m
checking for Python library path... -L/home/swapneil/anaconda3/lib -lpython3.6m
checking for Python site-packages path... /home/swapneil/anaconda3/lib/python3.6/site-packages
checking python extra libraries... -lpthread -ldl -lutil -lrt -lm
checking python extra linking flags... -Xlinker -export-dynamic
checking consistency of all components of python development environment... yes
checking for python version... 3.6
checking for python platform... linux
checking for python script directory... ${prefix}/lib/python3.6/site-packages
checking for python extension module directory... ${exec_prefix}/lib/python3.6/site-packages
checking for git... /usr/bin/git
checking python module: sphinx... yes
checking python module: sphinx_rtd_theme... no
checking for dbus-run-session... /home/swapneil/anaconda3/bin/dbus-run-session
checking for pkg-config... no
checking for DBUS... no
configure: error: in `/tmp/pip-install-b_jnkttm/dbus-python/build/temp.linux-x86_64-3.6':
configure: error: The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
Alternatively, you may set the environment variables DBUS_CFLAGS
and DBUS_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
To get pkg-config, see http://pkg-config.freedesktop.org/.
See `config.log' for more details
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-install-b_jnkttm/dbus-python/setup.py", line 109, in
tests_require=['tap.py'],
File "/home/swapneil/anaconda3/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/swapneil/anaconda3/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/home/swapneil/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/swapneil/anaconda3/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 179, in run
self.run_command('build')
File "/home/swapneil/anaconda3/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/swapneil/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/tmp/pip-install-b_jnkttm/dbus-python/setup.py", line 62, in run
cwd=builddir)
File "/home/swapneil/anaconda3/lib/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/tmp/pip-install-b_jnkttm/dbus-python/configure', '--disable-maintainer-mode', 'PYTHON=/home/swapneil/anaconda3/bin/python', '--prefix=/tmp/pip-install-b_jnkttm/dbus-python/build/temp.linux-x86_64-3.6/prefix']' returned non-zero exit status 1.
Failed building wheel for dbus-python
Running setup.py clean for dbus-python
Failed to build dbus-python
Installing collected packages: dbus-python
Running setup.py install for dbus-python ... error
Complete output from command /home/swapneil/anaconda3/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-install-b_jnkttm/dbus-python/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-ud25fz6o/install-record.txt --single-version-externally-managed --compile:
running install
running build
creating /tmp/pip-install-b_jnkttm/dbus-python/build
creating /tmp/pip-install-b_jnkttm/dbus-python/build/temp.linux-x86_64-3.6
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define EXTENSIONS... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking whether UID '1000' is supported by ustar format... yes
checking whether GID '1000' is supported by ustar format... yes
checking how to create a ustar tar archive... gnutar
checking dependency style of gcc... gcc3
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for native Windows host... no
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @file support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for inline... inline
checking for gawk... (cached) mawk
checking for python... /home/swapneil/anaconda3/bin/python
checking for a version of Python >= '2.1.0'... yes
checking for a version of Python >= '2.7'... yes
checking for the distutils Python package... yes
checking for Python include path... -I/home/swapneil/anaconda3/include/python3.6m
checking for Python library path... -L/home/swapneil/anaconda3/lib -lpython3.6m
checking for Python site-packages path... /home/swapneil/anaconda3/lib/python3.6/site-packages
checking python extra libraries... -lpthread -ldl -lutil -lrt -lm
checking python extra linking flags... -Xlinker -export-dynamic
checking consistency of all components of python development environment... yes
checking for python version... 3.6
checking for python platform... linux
checking for python script directory... ${prefix}/lib/python3.6/site-packages
checking for python extension module directory... ${exec_prefix}/lib/python3.6/site-packages
checking for git... /usr/bin/git
checking python module: sphinx... yes
checking python module: sphinx_rtd_theme... no
checking for dbus-run-session... /home/swapneil/anaconda3/bin/dbus-run-session
checking for pkg-config... no
checking for DBUS... no
configure: error: in `/tmp/pip-install-b_jnkttm/dbus-python/build/temp.linux-x86_64-3.6':
configure: error: The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
Alternatively, you may set the environment variables DBUS_CFLAGS
and DBUS_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
To get pkg-config, see <http://pkg-config.freedesktop.org/>.
See `config.log' for more details
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-b_jnkttm/dbus-python/setup.py", line 109, in <module>
tests_require=['tap.py'],
File "/home/swapneil/anaconda3/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/swapneil/anaconda3/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/home/swapneil/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/swapneil/anaconda3/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/home/swapneil/anaconda3/lib/python3.6/distutils/command/install.py", line 545, in run
self.run_command('build')
File "/home/swapneil/anaconda3/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/swapneil/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/tmp/pip-install-b_jnkttm/dbus-python/setup.py", line 62, in run
cwd=builddir)
File "/home/swapneil/anaconda3/lib/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/tmp/pip-install-b_jnkttm/dbus-python/configure', '--disable-maintainer-mode', 'PYTHON=/home/swapneil/anaconda3/bin/python', '--prefix=/tmp/pip-install-b_jnkttm/dbus-python/build/temp.linux-x86_64-3.6/prefix']' returned non-zero exit status 1.
----------------------------------------
Command "/home/swapneil/anaconda3/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-install-b_jnkttm/dbus-python/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-ud25fz6o/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-b_jnkttm/dbus-python/
Hello!
This is not actually an issue, and more of a heads up, but I've packaged python-networkmanager for Fedora.
Setip4/Setip6 may need preprocessing.
The NM_CONNECTIVITY_* flags are mapped incorrectly.
The correct definition is:
https://people.freedesktop.org/~lkundrak/nm-docs/nm-dbus-types.html#NMConnectivityState
however the values defined in the api are 0 indexed:
https://github.com/seveas/python-networkmanager/blob/master/NetworkManager.py#L751-L755
>>> device.DeviceType
1
is not very cool. I suggest to use Enum
(https://pypi.python.org/pypi/enum34).
NetworkManager 0.9.10+ supports new device types:
Here is a trivial patch adding two more constants. Thank you for applying it.
From 6bd6431f0bf5e30fb21c85d1d9fb920a7104b088 Mon Sep 17 00:00:00 2001
From: Adrian <[email protected]>
Date: Wed, 4 Mar 2015 13:45:42 +0100
Subject: [PATCH] Add 2 new device types
---
NetworkManager.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/NetworkManager.py b/NetworkManager.py
index b4b9aa1..f01bb76 100644
--- a/NetworkManager.py
+++ b/NetworkManager.py
@@ -422,6 +422,8 @@ NM_DEVICE_TYPE_BOND = 10
NM_DEVICE_TYPE_VLAN = 11
NM_DEVICE_TYPE_ADSL = 12
NM_DEVICE_TYPE_BRIDGE = 13
+NM_DEVICE_TYPE_GENERIC = 14
+NM_DEVICE_TYPE_TEAM = 15
NM_DEVICE_CAP_NONE = 0
NM_DEVICE_CAP_NM_SUPPORTED = 1
NM_DEVICE_CAP_CARRIER_DETECT = 2
--
1.9.1
I got the following error when selecting a profile in the applet menu due to UTF-8 characters being handled as ascii by default in Python 2.x.
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/commotion_applet_support.py", line 314, in choose_profile
connections = dict([(x.GetSettings()['connection']['id'], x) for x in connections])
File "/usr/lib/python2.7/dist-packages/NetworkManager.py", line 102, in proxy_call
return self.unwrap(ret)
File "/usr/lib/python2.7/dist-packages/NetworkManager.py", line 65, in unwrap
d[k] = self.unwrap(v)
File "/usr/lib/python2.7/dist-packages/NetworkManager.py", line 65, in unwrap
d[k] = self.unwrap(v)
File "/usr/lib/python2.7/dist-packages/NetworkManager.py", line 76, in unwrap
return str(val)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 2: ordinal not in range(128)
This was due to a profile in NetworkManager with an å
(00E5, http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=00E5&mode=hex ) in the name, more exactly the sv_SE locale's default name Trådbunden anslutning
in Network manager.
Until it's fixed one can easily work around it by renaming any non-ascii profiles to compatible names.
Hello everyone,
I'm trying to add connection to NetworkManager via python-networkmanager and got dbus.exceptions.DBusException: org.freedesktop.NetworkManager.Settings.Connection.InvalidProperty: 802-11-wireless-security.psk: property is invalid
In your examples, an open network is created, but I want to add secure network. My code looks like this:
def add_network(self, ssid, password):
connection = {
'802-11-wireless': {
'mode': 'infrastructure',
'ssid': ssid
},
'802-11-wireless-security': {
'key-mgmt': 'wpa-psk',
'auth-alg': 'open',
'psk': password,
},
'connection': {
'id': ssid,
'type': '802-11-wireless',
'uuid': str(uuid.uuid4())
},
'ipv4': {'method': 'auto'},
'ipv6': {'method': 'auto'}
}
NetworkManager.Settings.AddConnection(connection)
Is this a bug in python-networkmanager or I'm just doing something wrong? Thank you.
diff --git a/NetworkManager.py b/NetworkManager.py
index 77cd73f..715fce8 100644
--- a/NetworkManager.py
+++ b/NetworkManager.py
@@ -140,9 +140,9 @@ class NetworkManager(NMDbusInterface):
settings = args[0]
for key in settings:
if 'mac-address' in settings[key]:
- settings[key]['mac-address'] = fixup.mac_to_dbus(settings['key']['mac-address'])
+ settings[key]['mac-address'] = fixups.mac_to_dbus(settings[key]['mac-address'])
if 'bssid' in settings[key]:
- settings[key]['bssid'] = fixup.mac_to_dbus(settings['key']['mac-address'])
+ settings[key]['bssid'] = fixups.mac_to_dbus(settings[key]['mac-address'])
if 'ssid' in settings.get('802-11-wireless', {}):
settings['802-11-wireless']['ssid'] = fixups.ssid_to_dbus(settings['802-11-wireless']['ssid'])
if 'ipv4' in settings:
Just a little convenience thing...
As there's nothing to download on http://pypi.python.org/pypi/python-networkmanager/0.9.1 easy_install complains that it can't find a download link.
ipv4 data is turned into human readable string by postprocess. Is the same needed for ipv6? Not sure as I have no nm-managed ipv6 connections.
If I try reset IP settings or wireles settings have error:
according to signature 'a{sa{sv}}': <class 'ValueError'>: Unable to guess signature from an empty list
#extract item from dict NetworkManager.NetworkManager.Settings.Connection
conn = self._list[name]
s = conn.GetSettings()
RemoveKey(s, 'ipv6') #this method remove extra keys without error
t = self._Type(name) #extract type from ['connection']['type']
RemoveKey(s, t)
RemoveKey(s, t + '-security')
#just try reset settings
conn.Update(s)
Hello, first of all, thank you for writing this library.
I am trying to use this on the rpi running python 3.5 in virtualenv.
When I try to import the netwokrmanager, I get below error.
File "<stdin>", line 1, in <module>
File "/home/pi/.pyenv/versions/touch-screen-3.5.2/lib/python3.5/site-packages/NetworkManager.py", line 282, in <module>
class NetworkManager(NMDbusInterface):
File "/home/pi/.pyenv/versions/touch-screen-3.5.2/lib/python3.5/site-packages/NetworkManager.py", line 147, in __new__
SignalDispatcher.args[(element.attrib['name'], item.attrib['name'])] = [(arg.attrib['name'], arg.attrib['type']) for arg in item]
File "/home/pi/.pyenv/versions/touch-screen-3.5.2/lib/python3.5/site-packages/NetworkManager.py", line 147, in <listcomp>
SignalDispatcher.args[(element.attrib['name'], item.attrib['name'])] = [(arg.attrib['name'], arg.attrib['type']) for arg in item]
KeyError: 'name'
Can you let me know what am I missing?
Release 2.0.0 broke the compatibility with the NetworkManager in Debian Jessie.
It's been fixed with cad4dc7. Thank you for the fix!
Could we have a 2.0.1 release uploaded to Pypi? 😄
@juanfont @berkovskyy @ctc @afreof
I'd like to change the license of python-networkmanager to the zlib license instead of GPL 3+. As you've all contributed patches to it, can you please indicate your approval by replying to this issue?
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgement in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
The setup.py
should mention dbus-python
as a required package. At least in the virtualenv
it wasn't installed by default.
Hello! I'm using a legacy system with Ubuntu 14.04 with upstart as the init system and was wondering if we can get this package working with dbus 1.6.
When installing I get this error:
configure: error: Package requirements (dbus-1 >= 1.8) were not met:
Requested 'dbus-1 >= 1.8' but version of dbus is 1.6.18
Got the following error.
ERROR:dbus.connection:Unable to set arguments ({u'802-3-ethernet': {u'auto-negotiate': False}, u'connection': {u'id': u'eth0', u'timestamp': 1537683468, u'type': u'802-3-ethernet', u'interface-name': u'eth0', u'uuid': u'c15deb3e-e4a9-44cb-a9ef-3d5b4c8b3d68'}, u'ipv4': {u'addresses': [[dbus.UInt32(906100746L), dbus.UInt32(24L), dbus.UInt32(33685514L)]], u'gateway': u'10.0.2.2', 'route-data': [{'dest': u'172.16.0.0', 'next-hop': u'172.25.73.161', 'prefix': 12}, {'dest': '192.168.32.0', 'next-hop': '192.168.30.1', 'prefix': 24}], u'dns': [dbus.UInt32(134744072L)], u'address-data': dbus.Array([{u'prefix': dbus.UInt32(24L), u'address': u'10.0.2.54'}], signature=dbus.Signature('a{sv}')), u'method': u'manual'}, u'ipv6': {u'method': u'auto'}},) according to signature u'a{sa{sv}}': <type 'exceptions.TypeError'>: Expected a string or unicode object
Traceback (most recent call last):
.............
self.connection.Update(self.settings)
File "", line 4, in Update
File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 145, in call
**keywords)
File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 641, in call_blocking
message.append(signature=signature, *args)
https://projects.gnome.org/NetworkManager/developers/migrating-to-09/spec.html gives me 404.
Should be probably be replaced with something like:
https://projects.gnome.org/NetworkManager/developers/api/09/spec.html
I called the file network.py instaed of wifi_monitor.py . Other examples like info.py works properly.
Traceback (most recent call last): File "network.py", line 42, in <module> main() File "network.py", line 15, in main for dev in NetworkManager.Device.all(): AttributeError: type object 'Device' has no attribute 'all'
I tried to run with python 2.7 and python3 and had the same result. Still available for any info.
If we use NetworkManager.NetworkManager.ActivateConnection(connections, device, "/")
when NetworkManager is down it would give error which is obvious.
However when the NetworkManager is started, it keeps on throwing the same error.
bus = dbus.SystemBus()
NM_BUSNAME = 'org.freedesktop.NetworkManager'
while True:
if bus.name_has_owner(NM_BUSNAME):
try:
print "Connecting to ", conn
NetworkManager.NetworkManager.ActivateConnection(connections[conn], device, "/")
except dbus.exceptions.DBusException as e:
print e
else:
print "NetworkManager bus not available"
print "Sleeping"
time.sleep(10.0)
and my output goes like this:
Connecting to <network>
Sleeping
NetworkManager bus not present
Sleeping
Connecting to <network>
org.freedesktop.DBus.Error.ServiceUnknown: The name :1.70 was not provided by any .service files
Sleeping
Connecting to <network>
org.freedesktop.DBus.Error.ServiceUnknown: The name :1.70 was not provided by any .service files
I am trying to install python-networkmanager on ubuntu 14.04 but I get this error
Collecting python-networkmanager
Requirement already satisfied: six in ./Envs/wifi_thesis/lib/python2.7/site-packages (from python-networkmanager)
Collecting dbus-python (from python-networkmanager)
Using cached dbus-python-1.2.4.tar.gz
Building wheels for collected packages: dbus-python
Running setup.py bdist_wheel for dbus-python ... error
Complete output from command /home/al/Envs/wifi_thesis/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ZROHqg/dbus-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpVDYMCApip-wheel- --python-tag cp27:
running bdist_wheel
running build
creating /tmp/pip-build-ZROHqg/dbus-python/build
creating /tmp/pip-build-ZROHqg/dbus-python/build/temp.linux-x86_64-2.7
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether UID '1000' is supported by ustar format... yes
checking whether GID '1000' is supported by ustar format... yes
checking how to create a ustar tar archive... gnutar
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for native Windows host... no
checking how to print strings... printf
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for inline... inline
checking whether /home/al/Envs/wifi_thesis/bin/python version is >= 2.6... yes
checking for /home/al/Envs/wifi_thesis/bin/python version... 2.7
checking for /home/al/Envs/wifi_thesis/bin/python platform... linux2
checking for /home/al/Envs/wifi_thesis/bin/python script directory... ${prefix}/lib/python2.7/site-packages
checking for /home/al/Envs/wifi_thesis/bin/python extension module directory... ${exec_prefix}/lib/python2.7/site-packages
configure: Using $PYTHON-config: /home/al/Envs/wifi_thesis/bin/python-config
checking for Python headers using /home/al/Envs/wifi_thesis/bin/python-config --includes... -I/home/al/Envs/wifi_thesis/local/include/python2.7 -I/home/al/Envs/wifi_thesis/local/include/python2.7
checking whether those headers are sufficient... no
configure: error: could not find Python headers
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-ZROHqg/dbus-python/setup.py", line 106, in <module>
'build_ext': BuildExt,
File "/home/al/Envs/wifi_thesis/local/lib/python2.7/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/home/al/Envs/wifi_thesis/local/lib/python2.7/site-packages/wheel/bdist_wheel.py", line 204, in run
self.run_command('build')
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/tmp/pip-build-ZROHqg/dbus-python/setup.py", line 62, in run
cwd=builddir)
File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/tmp/pip-build-ZROHqg/dbus-python/configure', '--disable-maintainer-mode', 'PYTHON=/home/al/Envs/wifi_thesis/bin/python', '--prefix=/tmp/pip-build-ZROHqg/dbus-python/build/temp.linux-x86_64-2.7/prefix']' returned non-zero exit status 1
----------------------------------------
Failed building wheel for dbus-python
Running setup.py clean for dbus-python
Failed to build dbus-python
Installing collected packages: dbus-python, python-networkmanager
Running setup.py install for dbus-python ... error
Complete output from command /home/al/Envs/wifi_thesis/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ZROHqg/dbus-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Q1R_MF-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/al/Envs/wifi_thesis/include/site/python2.7/dbus-python:
running install
running build
creating /tmp/pip-build-ZROHqg/dbus-python/build
creating /tmp/pip-build-ZROHqg/dbus-python/build/temp.linux-x86_64-2.7
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether UID '1000' is supported by ustar format... yes
checking whether GID '1000' is supported by ustar format... yes
checking how to create a ustar tar archive... gnutar
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for native Windows host... no
checking how to print strings... printf
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for inline... inline
checking whether /home/al/Envs/wifi_thesis/bin/python version is >= 2.6... yes
checking for /home/al/Envs/wifi_thesis/bin/python version... 2.7
checking for /home/al/Envs/wifi_thesis/bin/python platform... linux2
checking for /home/al/Envs/wifi_thesis/bin/python script directory... ${prefix}/lib/python2.7/site-packages
checking for /home/al/Envs/wifi_thesis/bin/python extension module directory... ${exec_prefix}/lib/python2.7/site-packages
configure: Using $PYTHON-config: /home/al/Envs/wifi_thesis/bin/python-config
checking for Python headers using /home/al/Envs/wifi_thesis/bin/python-config --includes... -I/home/al/Envs/wifi_thesis/local/include/python2.7 -I/home/al/Envs/wifi_thesis/local/include/python2.7
checking whether those headers are sufficient... no
configure: error: could not find Python headers
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-ZROHqg/dbus-python/setup.py", line 106, in <module>
'build_ext': BuildExt,
File "/home/al/Envs/wifi_thesis/local/lib/python2.7/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/home/al/Envs/wifi_thesis/local/lib/python2.7/site-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/usr/lib/python2.7/distutils/command/install.py", line 601, in run
self.run_command('build')
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/tmp/pip-build-ZROHqg/dbus-python/setup.py", line 62, in run
cwd=builddir)
File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/tmp/pip-build-ZROHqg/dbus-python/configure', '--disable-maintainer-mode', 'PYTHON=/home/al/Envs/wifi_thesis/bin/python', '--prefix=/tmp/pip-build-ZROHqg/dbus-python/build/temp.linux-x86_64-2.7/prefix']' returned non-zero exit status 1
----------------------------------------
Command "/home/al/Envs/wifi_thesis/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ZROHqg/dbus-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Q1R_MF-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/al/Envs/wifi_thesis/include/site/python2.7/dbus-python" failed with error code 1 in /tmp/pip-build-ZROHqg/dbus-python/
How can I fix this?
Package should include the D-BUS API constants for NetworkManager.
https://developer.gnome.org/NetworkManager/1.2/nm-dbus-types.html
Sometimes I get this error. Very unclear how this happens. At the same time nmcli
can list networks fine... 🤔
Signal arguments should be postprocessed too
ERROR:dbus.connection:Exception in handler for D-Bus signal:
Traceback (most recent call last):
File "/home/gijs/Work/python-eduvpn-client/.virtualenv3/lib/python3.5/site-packages/dbus/connection.py", line 230, in maybe_handle_message
self._handler(*args, **kwargs)
File "/home/gijs/Work/python-eduvpn-client/.virtualenv3/lib/python3.5/site-packages/NetworkManager.py", line 77, in handle_signal
receiver(sender, *(sargs + rargs), **rkwargs)
TypeError: can only concatenate list (not "tuple") to list
version details:
dbus-python==1.2.4
python-networkmanager==2.0.1
I just built a Debian package from the latest in git as of now, and installed it to test against the commotion-mesh-applet. It seems that the code for generating the IP addresses is not generating valid IP addresses:
Traceback (most recent call last):
File "/media/share/code/opentechinstitute/commotion-mesh-applet/commotion_applet_support.py", line 314, in choose_profile
connections = dict([(x.GetSettings()['connection']['id'], x) for x in connections])
File "/usr/lib/python2.7/dist-packages/NetworkManager.py", line 93, in proxy_call
return self.postprocess(name, ret)
File "/usr/lib/python2.7/dist-packages/NetworkManager.py", line 137, in postprocess
for addr in val['ipv4']['addresses']]
socket.error: packed IP wrong length for inet_ntoa
This is the code that produces that:
connections = NetworkManager.Settings.ListConnections()
connections = dict([(x.GetSettings()['connection']['id'], x) for x in connections])
pi@raspberrypi:~/python-networkmanager/examples $ sudo python info.py
Traceback (most recent call last):
File "info.py", line 6, in
import NetworkManager
File "build/bdist.linux-armv7l/egg/NetworkManager.py", line 281, in
File "build/bdist.linux-armv7l/egg/NetworkManager.py", line 132, in new
File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 241, in get_object
follow_name_owner_changes=follow_name_owner_changes)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 248, in init
self._named_service = conn.activate_name_owner(bus_name)
File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 180, in activate_name_owner
self.start_service_by_name(bus_name)
File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 278, in start_service_by_name
'su', (bus_name, flags)))
File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.NetworkManager was not provided by any .service files
Hi, i have an error when i launch example on raspbian jessie with python 2.7, dbus-python 1.2.4
thanks
generating a source tarball with python setup.py sdist
does not include the docs/Makefile or docs/conf.py. Those files need to be in the source tarball to be included in the official debian package.
There is already a Debian Bug Report for this, both for python and python3.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=896281
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=896343
After installing python-networkmanager importing the module NetworkManager
into a python interpreter fails with the following error:
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/dist-packages/NetworkManager.py", line 99, in
init_bus = dbus.SystemBus(private=True)
File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 194, in new
private=private)
File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 100, in new
bus = BusConnection.new(subclass, bus_type, mainloop=mainloop)
File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 122, in new
bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.FileNotFound: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
How do I retrieve error messages from NetworkManager?
I'm just doing AddAndActivateConnection
call to the NetworkManager
, however, regardless of password I am entering I'm not getting any exceptions or error messages back. When using the nmcli command line client to do the same thing I get a nice error message like so:
Error: Connection activation failed: (7) Secrets were required, but not provided.
How do I check whether activating a connection succeeded, and if it did not, the error message?
I also posted a question on stackoverflow if you feel that's more appropriate! :-)
Hi,
I'm trying to write a small script to temporarily switch autoconnect property to a selected Ethernet connection. Here's a code I'm testing this with:
import NetworkManager
for conn in NetworkManager.Connection.all():
settings = conn.GetSettings()
if settings['connection']['type'] != '802-3-ethernet':
continue
cid = settings['connection']['id']
ac = settings['connection'].get('autoconnect', True)
changed = False
if cid == '192.168.1.20' and not ac:
del settings['connection']['autoconnect']
changed = True
elif ac:
settings['connection']['autoconnect'] = False
changed = True
if changed:
conn.UpdateUnsaved(settings)
As you can see it's nothing complicated (in the final version it would of course use command line args). Unfortunately, as soon as it tries to call conn.UpdateUnsaved(settings)
I get following error:
ERROR:dbus.connection:Unable to set arguments ({'802-3-ethernet': {'auto-negotiate': False, 'mac-address': [dbus.Byte(8), dbus.Byte(98), dbus.Byte(102), dbus.Byte(86), dbus.Byte(239), dbus.Byte(31)]}, 'connection': {'id': '192.168.1.20', 'uuid': '088509ff-0a6b-4c10-a9f6-70e4d6340f0b', 'type': '802-3-ethernet', 'permissions': ['user:yawor:'], 'timestamp': 1493193712}, 'ipv6': {'method': 'ignore', 'addr-gen-mode': 0}, 'ipv4': {'method': 'manual', 'addresses': [[dbus.UInt32(335653056), dbus.UInt32(24), dbus.UInt32(0)]], 'address-data': [{'address': '192.168.1.20', 'prefix': 24}]}},) according to signature 'a{sa{sv}}': <class 'TypeError'>: Expected a string or unicode object
Traceback (most recent call last):
File "test.py", line 21, in <module>
conn.UpdateUnsaved(settings)
File "<string>", line 4, in UpdateUnsaved
File "/home/yawor/Projects/NMTest/lib/python3.6/site-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "/home/yawor/Projects/NMTest/lib/python3.6/site-packages/dbus/connection.py", line 641, in call_blocking
message.append(signature=signature, *args)
TypeError: Expected a string or unicode object
Value of settings in that call is:
{'802-3-ethernet': {'auto-negotiate': False, 'mac-address': '08:62:66:56:EF:1F', 'mac-address-blacklist': [], 's390-options': {}}, 'connection': {'id': '192.168.1.20', 'uuid': '088509ff-0a6b-4c10-a9f6-70e4d6340f0b', 'type': '802-3-ethernet', 'permissions': ['user:yawor:'], 'timestamp': 1493193712}, 'ipv6': {'method': 'ignore', 'dns': [], 'dns-search': [], 'addresses': [], 'routes': [], 'addr-gen-mode': 0, 'address-data': [], 'route-data': []}, 'ipv4': {'method': 'manual', 'dns': [], 'dns-search': [], 'addresses': [['192.168.1.20', 24, '0.0.0.0']], 'routes': [], 'address-data': [{'address': '192.168.1.20', 'prefix': 24}], 'route-data': []}, 'proxy': {}}
I'm using ArchLinux with NetworkManager 1.6.2-3, python 3.6 and python-networkmanager version 2.0.1.
If you need more information please feel free to ask. I can do more tests if needed.
currently I think you need to do this, initialise the dbus main loop before importing network manager:
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
DBusGMainLoop(set_as_default=True)
import NetworkManager
def callback(*args, **kwargs): pass
loop = GLib.MainLoop()
NetworkManager.NetworkManager.connect_to_signal('PropertiesChanged', callback)
loop.run()
I guess this is because some GBus logic is already initialized during import. if you don't set up the dbus main loop before the network manager import an error is raised:
RuntimeError: To make asynchronous calls, receive signals or export objects, D-Bus connections must be attached to a main loop by passing mainloop=... to the constructor or calling dbus.set_default_main_loop(...)
I've noticed the project is missing a license. I'm interested in using python-networkmanager, but can't, unless it has an explicit license file.
The Ip4Address property of a device is not converted to string format. Adding the following postprocess function to class Device solves the problem:
@@ -213,6 +213,11 @@ class Device(NMDbusInterface):
NM_DEVICE_TYPE_ADSL: Adsl,
}[self.DeviceType](self.object_path)
+ def postprocess(self, name, val):
+ if name == 'Ip4Address':
+ val = fixups.addr_to_python(val)
+ return val
+
First off, thanks for a great library.
I have one really big nit. Normally in python modules when you import then they define functions and classes, but does not execute code. This happens when you call functions or create objects. However, with NetworkManager, it starts making dbus calls and shit as soon as I import the module. This cannot be right, and causes huge issues. On our buildserver for example there is no network-manager running and your nice library NetworkManager cannot even be imported, even though the tests never calls a single function from the module, but merely imports it.
You can still have singletons, but that are created lazily using e.g. a static function in the NetworkManager class like so
NetworkManager.NetworkManager.get_instance()
This would resolve many problems for me (and probably others) and make this awesome NetworkManager module work more like a normal python module.
Hi!
I was trying to use the current version of your library for a project on a Debian 8.7 (NetworkManager: 0.9.10.0-7) host.
While running the wifi_monitor example, I encountered this:
ERROR:dbus.connection:Exception in handler for D-Bus signal:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/dbus/connection.py", line 230, in maybe_handle_message
self._handler(*args, **kwargs)
File "/usr/lib/python3/dist-packages/NetworkManager.py", line 77, in handle_signal
receiver(sender, *(sargs + rargs), **rkwargs)
TypeError: can only concatenate list (not "tuple") to list
I have since figured out that 'rargs` seems to be a tuple at that point.
What can I do to fix this?
ERROR:dbus.connection:Unable to set arguments ({u'802-3-ethernet': {u's390-options': {}}, u'connection': {u'id': u'ethernet-eth0', u'timestamp': 1420558638, u'type': u'802-3-ethernet', u'uuid': 'dc38e52a-89e9-4c8c-93af-ad3e2bdd98dd', u'interface-name': u'eth0'}, u'ipv4': {u'routes': [], u'addresses': [[dbus.UInt32(1653084332L), dbus.UInt32(24L), dbus.UInt32(25694380L)]], u'dns': [], u'method': u'manual'}, u'ipv6': {u'routes': [], u'addresses': [], u'dns': [], u'method': u'ignore'}}, dbus.ObjectPath('/org/freedesktop/NetworkManager/Devices/1'), '/') according to signature u'a{sa{sv}}oo': <type 'exceptions.ValueError'>: Unable to guess signature from an empty dict
[' File "/usr/lib/pymodules/python2.7/Mgs/NetworkInterface.py", line 105, in __activate_connection\n active_conn = NetworkManager.NetworkManager.AddAndActivateConnection(conn_settings, self.nm_device.object_path, "/")\n', ' File "/usr/lib/python2.7/dist-packages/NetworkManager.py", line 115, in proxy_call\n ret = func(*args, **kwargs)\n', ' File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__\n **keywords)\n', ' File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 641, in call_blocking\n message.append(signature=signature, *args)\n']
Unable to guess signature from an empty dict
I'm trying to execute AddAndActiveConnection, but I can't pass input parameters that are/contain an empty list/dict, because of the a{sv} signature. I've written a small function to replace empty lists and dicts by their dbus variant, but the parsing of the input parameters within python-networkmanager undoes what I parsed.
This function can be added to this lib, or maybe somebody has a better idea?
Settings.Update should be preprocess()
ed like AddConnection. AddAndActivateConnection may need work too.
First of all there is a typo which is an easy fix:
AttributeError: 'module' object has no attribute 'Networkmanager'
When I change it to:
import NetworkManager
NetworkManager.NetworkManager.Version
NetworkManager.NetworkManager.GetPermissions()
import dbus.mainloop.glib
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
def handle_state_change(*args, **kwargs): pass
NetworkManager.NetworkManager.OnStateChanged(handle_state_change)
I get the error:
TypeError: Don't know which D-Bus type to use to encode type "function"
network manager version 1.4.4
I want to execute my code after a connection is enabled and before it gets disabled. (Similar to the NetworkManager-Dispatcher events up
and pre-down
.
In addition i want the Connection object of the changing connection. (i need to compare the uuids).
How can i accomplish this?
NetworkManager.NetworkManager.OnStateChanged
does not contain information which connection changed.
Furthermore how could i do something like pre-down
, as the NetworkManager API doesn't seem to have a signal/event like this?
I was trying out python-networkmanager/examples/info.py
but received the following permission issue. How do i overcome this permission issue? I tried the script in Ubuntu 16.04 with python 3.6.7, and with existing NetworkManager service enabled and disabled.
Traceback (most recent call last):
File "~/git/test_networkmanager.py", line 45, in <module>
for conn in NetworkManager.Settings.ListConnections():
File "<string>", line 8, in ListConnections
File "~/.local/share/virtualenvs/git-icaXKgBz/lib/python3.6/site-packages/NetworkManager.py", line 550, in to_python
val = fixups.base_to_python(val)
File "~/.local/share/virtualenvs/git-icaXKgBz/lib/python3.6/site-packages/NetworkManager.py", line 607, in base_to_python
return [fixups.base_to_python(x) for x in val]
File "~/.local/share/virtualenvs/git-icaXKgBz/lib/python3.6/site-packages/NetworkManager.py", line 607, in <listcomp>
return [fixups.base_to_python(x) for x in val]
File "~/.local/share/virtualenvs/git-icaXKgBz/lib/python3.6/site-packages/NetworkManager.py", line 620, in base_to_python
return globals()[classname](val)
File "~/.local/share/virtualenvs/git-icaXKgBz/lib/python3.6/site-packages/NetworkManager.py", line 304, in __init__
self.uuid = self.GetSettings()['connection']['uuid']
File "<string>", line 3, in GetSettings
File "~/.local/share/virtualenvs/git-icaXKgBz/lib/python3.6/site-packages/dbus/proxies.py", line 70, in __call__
return self._proxy_method(*args, **keywords)
File "~/.local/share/virtualenvs/git-icaXKgBz/lib/python3.6/site-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "~/.local/share/virtualenvs/git-icaXKgBz/lib/python3.6/site-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.NetworkManager.Settings.PermissionDenied: uid 1000 has no permission to perform this operation
I am trying to install python-networkmanager with the following command:
pip install python-networkmanager
But I get this error:
Collecting python-networkmanager
Collecting six (from python-networkmanager)
Using cached six-1.11.0-py2.py3-none-any.whl
Collecting dbus-python (from python-networkmanager)
Using cached dbus-python-1.2.4.tar.gz
Installing collected packages: six, dbus-python, python-networkmanager
Running setup.py install for dbus-python ... error
Complete output from command c:\users\al\appdata\local\programs\python\pytho
n36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\AL\\AppDa
ta\\Local\\Temp\\pip-build-t2n5ncjb\\dbus-python\\setup.py';f=getattr(tokenize,
'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compi
le(code, __file__, 'exec'))" install --record C:\Users\AL\AppData\Local\Temp\pip
-rteq2hs5-record\install-record.txt --single-version-externally-managed --compil
e:
running install
running build
creating C:\Users\AL\AppData\Local\Temp\pip-build-t2n5ncjb\dbus-python\build
creating C:\Users\AL\AppData\Local\Temp\pip-build-t2n5ncjb\dbus-python\build
\temp.win-amd64-3.6
error: [WinError 193] %1 is not a valid Win32 application
----------------------------------------
Command "c:\users\al\appdata\local\programs\python\python36\python.exe -u -c "im
port setuptools, tokenize;__file__='C:\\Users\\AL\\AppData\\Local\\Temp\\pip-bui
ld-t2n5ncjb\\dbus-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);
code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec
'))" install --record C:\Users\AL\AppData\Local\Temp\pip-rteq2hs5-record\install
-record.txt --single-version-externally-managed --compile" failed with error cod
e 1 in C:\Users\AL\AppData\Local\Temp\pip-build-t2n5ncjb\dbus-python\
How I can solve this? Thanks
Hey, trying to add an IPv6 connection like this:
connection = {
'802-3-ethernet': {'mac-address': mac_address,
'mac-address-blacklist': a_blacklist},
'connection': {'autoconnect': True,
'id': 'myid',
'type': '802-3-ethernet',
'uuid': some_UUID},
}
addr1 = dbus.Dictionary({
'address': 'fec0::1',
'prefix': dbus.UInt32(64)})
connection['ipv6'] = dbus.Dictionary({
'address-data': dbus.Array([addr1], signature=dbus.Signature('a{sv}')),
'gateway': '::',
'method': 'shared'})
NetworkManager.Settings.AddConnection(connection)
But I'm getting the following:
ValueError: invalid literal for long() with base 10: 'fec0::1'
Can someone please tell me where is my mistake here? Thanks!
Description of problem:
When adding a new connection with manual IPv4 settings it fails because of invalid type. However, according to nm-settings documentation I'm using it right (correct me if I am wrong). "Array of IPv4 addresses. Each address dictionary contains at least 'address' and 'prefix' entries, containing the IP address as a string, and the prefix length as a uint32."
Version-Release number of selected component (if applicable):
python-networkmanager (2.0.1)
Python 3.4.5
How reproducible:
Always
Steps to Reproduce:
'ipv4': {
'method': 'manual',
'address-data': [{'address': '192.168.1.1', 'prefix': 24}]
}
Actual results:
Fails with "TypeError: Expected a string or unicode object"
Expected results:
Creates a connection with static IP.
Reproduction:
[root@localhost ~]# python3
>>> import NetworkManager
>>> import uuid
>>> bridge_with_manual_ip = {
... 'connection': {
... 'id': 'br1',
... 'uuid': str(uuid.uuid4()),
... 'type': 'bridge',
... 'interface-name': 'br1'
... },
... 'ipv4': {
... 'method': 'manual',
... 'address-data': [{'address': '192.168.1.1', 'prefix': 24}]
... }
... }
>>> NetworkManager.Settings.AddConnection(bridge_with_manual_ip)
ERROR:dbus.connection:Unable to set arguments ({'ipv4': {'address-data': [{'address': '192.168.1.1', 'prefix': 24}], 'method': 'manual'}, 'connection': {'type': 'bridge', 'interface-name': 'br1', 'uuid': '240f360c-f005-4be1-b2ab-adfb596ac7e7', 'id': 'br1'}},) according to signature 'a{sa{sv}}': <class 'TypeError'>: Expected a string or unicode object
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 4, in AddConnection
File "/usr/lib64/python3.4/site-packages/dbus/proxies.py", line 70, in __call__
return self._proxy_method(*args, **keywords)
File "/usr/lib64/python3.4/site-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "/usr/lib64/python3.4/site-packages/dbus/connection.py", line 641, in call_blocking
message.append(signature=signature, *args)
TypeError: Expected a string or unicode object
At least on a 64Bit system there are problems with IP address and IP netmask encoding. Applying the following patch works on a 32Bit and on a 64Bit x86 system.
@@ -342,7 +342,7 @@ class fixups(object):
addr, netmask, gateway = addrconf
return [
fixups.addr_to_dbus(addr),
- netmask,
+ fixups.mask_to_dbus(netmask),
fixups.addr_to_dbus(gateway)
]
@@ -352,7 +352,11 @@ class fixups(object):
@staticmethod
def addr_to_dbus(addr):
- return struct.unpack('I', socket.inet_aton(addr))
+ return dbus.UInt32(struct.unpack('I', socket.inet_aton(addr))[0])
+
+ @staticmethod
+ def mask_to_dbus(mask):
+ return dbus.UInt32(mask)
@staticmethod
def route_to_python(route):
@@ -369,7 +373,7 @@ class fixups(object):
addr, netmask, gateway, metric = route
return [
fixups.addr_to_dbus(addr),
- netmask,
+ fixups.mask_to_dbus(netmask),
fixups.addr_to_dbus(gateway),
socket.htonl(metric)
]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.