From 2dea8bb2135071675f044a5f973ff2ebef1beb87 Mon Sep 17 00:00:00 2001 From: Chris Lunsford Date: Mon, 3 Oct 2016 22:07:32 -0400 Subject: [PATCH] Fix bug #11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correct RestSession.get_items() to check for the existence of a JSON ‘items’ attribute by checking to see ‘if items is None’ instead of just checking for ‘if items’, which incorrectly raises the error when ‘items’ is present but is an empty array. --- ciscosparkapi/restsession.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ciscosparkapi/restsession.py b/ciscosparkapi/restsession.py index 484c292..be6cb51 100644 --- a/ciscosparkapi/restsession.py +++ b/ciscosparkapi/restsession.py @@ -144,13 +144,13 @@ def get_items(self, url, params=None, **kwargs): # objects contained within the top level 'items' array assert isinstance(json_page, dict) items = json_page.get(u'items') - if items: - for item in items: - yield item - else: + if items is None: error_message = "'items' object not found in JSON data: " \ "{!r}".format(json_page) raise ciscosparkapiException(error_message) + else: + for item in items: + yield item def post(self, url, json, **kwargs): # Process args