device_inventory.py - KeyError looking at response
When trying to use the inventory.add_devices, it raises a KeyError:
result = inventory.add_devices(ac, all_devices) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".venv/lib/python3.12/site-packages/pycentral/classic/device_inventory.py", line 252, in add_devices Message - {resp["msg"]["detail"]}') ~~~~~~~~~~~^^^^^^^^^^ KeyError: 'detail'
-- My code: from pycentral.base import ArubaCentralBase from pycentral.device_inventory import Inventory
ac = ArubaCentralBase(central_info=central_info) inventory = Inventory() all_devices = switch_devices + wifi_devices result = inventory.add_devices(ac, all_devices)
I have upgraded to the latest pycentral package of 2.0.0a2 and still get this issue.
@mrzepa Not sure if this was bug in pycentral-2.0.0a2. But in pycentral-2.0a5, i dont see this problem
from pycentral.base import ArubaCentralBase
from pprint import pprint
from pycentral.classic.device_inventory import Inventory
central_info = {
"base_url": "https://xyz.hpe.com",
"token": {
"access_token": "ABCDEFG"
}
}
ssl_verify = True
central = ArubaCentralBase(central_info=central_info, ssl_verify=ssl_verify)
device_inventory = Inventory()
device_list = device_inventory.get_inventory(central)
pprint(device_list)
print("--------------------------------------------------")
device_details = [{"mac": "5A:5A:5A:5A:5A:5A", "serial": "XYZ1234567"}]
add_device_output = device_inventory.add_devices(central, device_details)
pprint(add_device_output)
print("--------------------------------------------------")
updated_device_list = device_inventory.get_inventory(central)
pprint(updated_device_list)
print("--------------------------------------------------")
In add_device_output response i was able to see device added, confirmed the same by visiting my /devices/inventory-list GLCP workspace
cc: @KarthikSKumar98
@KarthikSKumar98 Do you think we should add this snippet to the /sample_scripts folder? If yes, I can quickly open a PR.