From a55dcaee83b0966bc9564e0a7996b6e1b4e922a6 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sat, 21 Jan 2023 09:22:43 +0100 Subject: T4911: op-mode: bugfix TypeError: string indices must be integers One can not always ensure that "capability" is of type list, add a safeguard. E.G. Unify US-24-250W only has a dict, not a list of dicts. --- src/op_mode/lldp.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/op_mode/lldp.py b/src/op_mode/lldp.py index dc2b1e0b5..c815ffcd4 100755 --- a/src/op_mode/lldp.py +++ b/src/op_mode/lldp.py @@ -80,6 +80,10 @@ def _get_formatted_output(raw_data): # Capabilities cap = '' capabilities = jmespath.search('chassis.[*][0][0].capability', values) + # One can not always ensure that "capability" is of type list, add + # safeguard. E.G. Unify US-24-250W only has a dict, not a list of dicts + if isinstance(capabilities, dict): + capabilities = [capabilities] if capabilities: for capability in capabilities: if capability['enabled']: -- cgit v1.2.3