From 33c3a02729ae95a8173f902cddd039c17262fbcb Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sun, 22 Jan 2023 08:20:10 +0100 Subject: T4911: op-mode: bugfix AttributeError: 'str' object has no attribute 'items' One can not always ensure that "interface" is of type list, add safeguard. E.G. Juniper Networks, Inc. ex2300-c-12t only has a dict, not a list of dicts So this is actually an upstream lldpd bug where the output depends on the amount of data transmitted. --- src/op_mode/lldp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/op_mode/lldp.py b/src/op_mode/lldp.py index bfcb8f8c7..1a1b94783 100755 --- a/src/op_mode/lldp.py +++ b/src/op_mode/lldp.py @@ -64,7 +64,11 @@ def _get_formatted_output(raw_data): tmp = dict_search('lldp.interface', raw_data) if not tmp: return None - for neighbor in dict_search('lldp.interface', raw_data): + # One can not always ensure that "interface" is of type list, add safeguard. + # E.G. Juniper Networks, Inc. ex2300-c-12t only has a dict, not a list of dicts + if isinstance(tmp, dict): + tmp = [tmp] + for neighbor in tmp: for local_if, values in neighbor.items(): tmp = [] -- cgit v1.2.3