diff options
-rw-r--r-- | gantools/ganbreeder.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/gantools/ganbreeder.py b/gantools/ganbreeder.py index a2546a2..40e58d3 100644 --- a/gantools/ganbreeder.py +++ b/gantools/ganbreeder.py @@ -52,13 +52,29 @@ def get_info(sid, key): cookies = { 'connect.sid': sid } - r = requests.get('http://artbreeder.com/info?k='+str(key), cookies=cookies) + url = 'http://artbreeder.com/info?k='+str(key) + r = requests.get(url, cookies=cookies) r.raise_for_status() - return parse_info_dict(r.json()) + + r = r.json() + if r is not None: + try: + return parse_info_dict(r) + except Exception as err: + print("Could not retrieve info for key \'{0}\': {1}".format(key, err)) + raise + else: + raise RuntimeError("No info could be found at URL \'{0}\'".format(url)) def get_info_batch(username, password, keys): l = list() sid = login(username, password) for key in keys: - l.append(get_info(sid, key)) + try: + l.append(get_info(sid, key)) + except Exception as err: + print("Encountered an error while attempting" + "to download info for key {0}".format(key)) + print("Error says: {}".format(err)) + print("Skipping...") return l |