python-sdbus / python-sdbus-networkmanager

python-sdbus binds for NetworkManager
GNU Lesser General Public License v2.1
28 stars 6 forks source link

"ConnectionType" is unknown import symbol #50

Closed Benik3 closed 1 year ago

Benik3 commented 1 year ago

Hello.

I'm new to python and I'm trying to use this module. I successfully installed it in venv under Visual Studio Code, but I'm not able to get the block example list-connections.py code to work. I get error "ConnectionType" is unknown import symboland Cannot access member "connection_profile" for type "NetworkConnectionSettings" Member "connection_profile" is unknown.

I'm using Ubuntu 22.04 with Python 3.10.6. Am I missing something?

image image image

igo95862 commented 1 year ago

Hello,

Most likely issue is that you installed version 1.1.0 from PyPI but the new examples require version 2.0

There is an 2.0RC1 version on PyPI but it must be installed explicitly.

./venv/bin/pip install sdbus-networkmanager==2.0rc1
Benik3 commented 1 year ago

You are right, pip automatically installed version 1.1.0. After forcing installation the 2.0RC1 the errors are gone. Thanks! But it looks like the example didn't run fully successfully:

{'connection': {'id': ('s', 'xxxx'), 'interface-name': ('s', 'wlp0s20f3'), 'permissions': ('as', []), 'timestamp': ('t', 1676880197), 'type': ('s', '802-11-wireless'), 'uuid': ('s', 'b9dd252a-569b-4c29-a8e3-dca0d504f847')}, '802-11-wireless': {'mac-address-blacklist': ('as', []), 'mode': ('s', 'infrastructure'), 'security': ('s', '802-11-wireless-security'), 'seen-bssids': ('as', ['00:17:C5:EE:YY:XX', '00:17:C5:EE:YY:XX', '00:17:C5:EE:YY:XX', '00:17:C5:EE:YY:XX', '00:17:C5:EE:YY:XX', '00:17:C5:EE:YY:XX']), 'ssid': ('ay', b'xxxx')}, '802-11-wireless-security': {'key-mgmt': ('s', 'wpa-eap')}, '802-1x': {'eap': ('as', ['peap']), 'identity': ('s', 'xxxx'), 'phase2-auth': ('s', 'mschapv2')}, 'ipv4': {'address-data': ('aa{sv}', []), 'dns-search': ('as', []), 'method': ('s', 'auto'), 'route-data': ('aa{sv}', [])}, 'ipv6': {'address-data': ('aa{sv}', []), 'dns-search': ('as', []), 'method': ('s', 'auto'), 'route-data': ('aa{sv}', [])}, 'proxy': {}}
Traceback (most recent call last):
  File "/home/benesd/Projekty/PythonNetworkManager/main.py", line 59, in <module>
    list_connection_profiles_blocking()
  File "/home/benesd/Projekty/PythonNetworkManager/main.py", line 30, in list_connection_profiles_blocking
    print_connection_profile_blocking(dbus_connection_path)
  File "/home/benesd/Projekty/PythonNetworkManager/main.py", line 35, in print_connection_profile_blocking
    profile = NetworkConnectionSettings(connection_path).connection_profile()
  File "/home/benesd/Projekty/PythonVenv/.venv/lib/python3.10/site-packages/sdbus_block/networkmanager/objects.py", line 221, in connection_profile
    return ConnectionProfile.from_dbus(self.get_settings())
  File "/home/benesd/Projekty/PythonVenv/.venv/lib/python3.10/site-packages/sdbus_block/networkmanager/settings/profile.py", line 419, in from_dbus
    raise e
  File "/home/benesd/Projekty/PythonVenv/.venv/lib/python3.10/site-packages/sdbus_block/networkmanager/settings/profile.py", line 414, in from_dbus
    unvarianted_options: Dict[str, Any] = {
  File "/home/benesd/Projekty/PythonVenv/.venv/lib/python3.10/site-packages/sdbus_block/networkmanager/settings/profile.py", line 415, in <dictcomp>
    SETTING_DBUS_NAME_TO_NAME[k]: SETTING_TO_CLASS[k].from_dbus(v)
  File "/home/benesd/Projekty/PythonVenv/.venv/lib/python3.10/site-packages/sdbus_block/networkmanager/settings/base.py", line 85, in from_dbus
    unvarianted_options = {
  File "/home/benesd/Projekty/PythonVenv/.venv/lib/python3.10/site-packages/sdbus_block/networkmanager/settings/base.py", line 86, in <dictcomp>
    reverse_mapping[k]: cls._unpack_variant(k, *v)
KeyError: 'security'

Note: I replaced some data with xxxx due to privacy

igo95862 commented 1 year ago

You probably need this commit 457949f745db8a45f81ac9e9970e45905c416bdc . It makes the settings class backwards and forwards compatible. It is more recent than 0.8RC1 version.

Benik3 commented 1 year ago

Hmm I tried to uninstall the pip version and install master version from git, but I ended even with not known sdbus_block.networkmanager. I will try to continue tomorrow :)

igo95862 commented 1 year ago

I will probably release 2.0.0 this weekend. (it will include that commit)

Benik3 commented 1 year ago

I finally got it solved. Before I installed the package using setup.py, which made just .egg. After correct install using pip from master branch, the example works fine :)

igo95862 commented 1 year ago

@Benik3 I did not have enough time to create 2.0.0 release this weekend.

However, I did upload the 2.0RC2 version to PyPI: https://pypi.org/project/sdbus-networkmanager/2.0rc2/

It should contain the necessary commit.