diff options
author | Vee9ahd1 <[email protected]> | 2021-05-10 20:15:04 -0400 |
---|---|---|
committer | Vee9ahd1 <[email protected]> | 2021-05-10 20:15:04 -0400 |
commit | ad8787812ae39bd2c6961c589a3eeb0ba357855c (patch) | |
tree | e299e9ca9dee1309714b1194fb871018b528058f /gantools/ganbreeder.py | |
parent | 02e16cfc050b180478176a61d7f7cdd5e72a1283 (diff) |
added some error handling for the case where artbreeder's api doesn't return any info for a given keyHEADmaster
Diffstat (limited to 'gantools/ganbreeder.py')
-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 |