From d6c7f690b7b65fc7d995dc3d739db355a4a6a2fd Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Sun, 21 Jun 2015 13:58:26 +0100 Subject: Fail gracefully on empty results --- src/fingerchange.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/fingerchange.py b/src/fingerchange.py index b34c009..952822f 100755 --- a/src/fingerchange.py +++ b/src/fingerchange.py @@ -23,7 +23,10 @@ def get_user_by_uid(site, uid): res = requests.get(api_url + str(uid), params=params) res = json.loads(res.text) - return res['items'][0] + if 'items' in res and len(res['items']) > 0: + return res['items'][0] + else: + return def get_users_by_name(site, name=''): @@ -35,7 +38,10 @@ def get_users_by_name(site, name=''): res = requests.get(api_url, params=params) res = json.loads(res.text) - return res['items'] + if 'items' in res: + return res['items'] + else: + return [] def format_url(url): -- cgit v1.2.3-70-g09d2