piwheels / packages

Issue tracker for piwheels package issues
https://github.com/piwheels/packages/issues
20 stars 5 forks source link

postpy2 File "postpy2\core.py", line 39, in __load for request in fol['item']: KeyError: 'item' #173

Closed motobeerx closed 3 years ago

motobeerx commented 3 years ago

Package name: example Link to PyPI page: https://pypi.org/project/postpy2/ Link to piwheels page: https://www.piwheels.org/project/postpy2/ Version: 0.0.6 Python version: 3.8 I am the maintainer: No More information: At using postpy2 library for working with postman, importing collection error during parsing. It simple try to get the key which does not exist. I tried to debug a little bit no success, everything is connected and I face keyerror on every step.

Please use code blocks where appropriate: def load(self): for fol in self.postman_collection['item']: requests_list = {} for request in fol['item']: if 'request' in request: request['request']['name'] = request['name'] requests_list[normalize_func_name( request['name'])] = PostRequest(self, request['request'])

via pycharm

I tried to run this code

from postpy2.core import PostPython
runner = PostPython(r"D:\Tamm\microservice-test-automation\adp\ADP.postman_collection.json")
runner.environments.load(r"D:\Tamm\microservice-test-automation\staging.postman_environment.json")
# runner.help()
response = runner.aadc.health_pass()
print(response.json())
print(response.status_code)
motobeerx commented 3 years ago

2020-11-30_14h56_58

the happens on 39 line. the fol['item'] is a list of dictionaries, and the key error happens because of : In: for x in self.__postman_collection['item']: print(x.keys())

Out: dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'item', 'event', 'protocolProfileBehavior']) dict_keys(['name', 'event', 'request', 'response']) the last dictionary doesn't have key 'item'

So is there any workaround/solution ? here's the structure of my postman collection:

2020-11-30_15h10_36

motobeerx commented 3 years ago

And the final thing I'd like to mention is that I suppose it happens because this little guy /health - pass GET request. P.S. Can this library read the global environments variables from file?

bennuttall commented 3 years ago

This issue tracker is for Raspberry Pi wheels on piwheels.org, not general issues with a library. Please take your issue up with the maintainers. You may find their github or contact details through PyPI: https://pypi.org/project/postpy2/