From 0cff7d3477dd1aa9e97bdeba5da919ca3b74b1fe Mon Sep 17 00:00:00 2001 From: illes Date: Mon, 18 Jul 2022 22:06:33 +0200 Subject: [PATCH] Fix module platform has no attribute linux_distribution (#224) --- netbox_agent/misc.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/netbox_agent/misc.py b/netbox_agent/misc.py index 6e7e92d..8672cad 100644 --- a/netbox_agent/misc.py +++ b/netbox_agent/misc.py @@ -32,12 +32,17 @@ def get_device_type(type): def get_device_platform(device_platform): if device_platform is None: try: - import platform + # Python 3.8+ moved linux_distribution() to distro + try: + import distro + linux_distribution = " ".join(distro.linux_distribution()) + except ImportError: + import platform + linux_distribution = " ".join(platform.linux_distribution()) - linux_distribution = " ".join(platform.linux_distribution()) if not linux_distribution: return None - except (ModuleNotFoundError, NameError): + except (ModuleNotFoundError, NameError, AttributeError): return None else: linux_distribution = device_platform