cumulocity-python-api icon indicating copy to clipboard operation
cumulocity-python-api copied to clipboard

KeyError when retrieving "bulkOperation "

Open zhaoyutongxue opened this issue 1 year ago • 0 comments

`def getOperation():

bos = c8y.bulk_operations.select(limit=3)

for bo in bos:
    print(bo.status)`

Hi Chris,

Hope you are well!

when I tried to run the above code to get "Bulk Operation" from Cumulocity, I encountered the below KeyError.

Traceback (most recent call last): File "C:\xxx\opt.py", line 3, in object4.getOperation() File "C:\xxx\operation\object4.py", line 9, in getOperation for bo in bos: File "C:\xxx\Lib\site-packages\c8y_api\model_base.py", line 556, in _iterate results = [parse_func(x) for x in self._get_page(base_query, current_page)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\xxx\Lib\site-packages\c8y_api\model_base.py", line 541, in _get_page return result_json[self.object_name] ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ KeyError: 'bulkoperations'

It looks to me the problem is: The key in the API response is: "bulkOperations" with capital "O".
But "_get_page return result_json[self.object_name]" is using "bulkoperations" as the key, with the lower case "o"

Hence the KeyError exception happened.

Regards Henry

zhaoyutongxue avatar Jun 01 '24 11:06 zhaoyutongxue