如何使用找到here的python-networkmanager库检索错误消息。
我正在import subprocess
a = 0
while True:
print(a)
a += 1
subprocess.call("clear")
拨打AddAndActivateConnection
来连接到WiFi接入点,就像这样。
NetworkManager
然而,无论我输入密码,我都没有收到任何异常或错误消息。当使用nmcli命令行客户端做同样的事情时,我得到一个很好的错误消息,如:
devices = NetworkManager.NetworkManager.GetDevices()
wifi = devices[0].SpecificDevice()
[access_point] = [ap for ap in wifi.GetAccessPoints() if ap.Ssid == 'foo']
connection_params = {
"802-11-wireless": {
"security": "802-11-wireless-security",
},
"802-11-wireless-security": {
"key-mgmt": "wpa-psk",
"psk": "Super Secret Password Goes Here"
},
}
NetworkManager.NetworkManager.AddAndActivateConnection(connection_params, wifi, access_point)
如何检查激活连接是否成功,如果没有,则显示错误消息?