diff options
Diffstat (limited to 'diplomacy/integration/webdiplomacy_net')
-rw-r--r-- | diplomacy/integration/webdiplomacy_net/api.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/diplomacy/integration/webdiplomacy_net/api.py b/diplomacy/integration/webdiplomacy_net/api.py index 8833b83..b4bde01 100644 --- a/diplomacy/integration/webdiplomacy_net/api.py +++ b/diplomacy/integration/webdiplomacy_net/api.py @@ -55,7 +55,11 @@ class API(BaseAPI): # 200 - Response OK if response.code == 200 and response.body: - list_games_players = json.loads(response.body.decode('utf-8')) + try: + list_games_players = json.loads(response.body.decode('utf-8')) + except (TypeError, ValueError): + LOGGER.warning('ERROR during "%s". Unable to load JSON: %s.', route, response.body.decode('utf-8')) + return return_val for game_player in list_games_players: return_val += [GameIdCountryId(game_id=game_player['gameID'], country_id=game_player['countryID'])] @@ -84,7 +88,11 @@ class API(BaseAPI): # 200 - Response OK if response.code == 200 and response.body: - list_games_players = json.loads(response.body.decode('utf-8')) + try: + list_games_players = json.loads(response.body.decode('utf-8')) + except (TypeError, ValueError): + LOGGER.warning('ERROR during "%s". Unable to load JSON: %s.', route, response.body.decode('utf-8')) + return return_val for game_player in list_games_players: return_val += [GameIdCountryId(game_id=game_player['gameID'], country_id=game_player['countryID'])] @@ -118,7 +126,11 @@ class API(BaseAPI): # 200 - Response OK if response.code == 200 and response.body: - state_dict = json.loads(response.body.decode('utf-8')) + try: + state_dict = json.loads(response.body.decode('utf-8')) + except (TypeError, ValueError): + LOGGER.warning('ERROR during "%s". Unable to load JSON: %s.', route, response.body.decode('utf-8')) + return return_val game, power_name = state_dict_to_game_and_power(state_dict, country_id, max_phases=max_phases) return_val = game, power_name @@ -201,7 +213,11 @@ class API(BaseAPI): return False # Otherwise, validating that received orders are the same as submitted orders - response_body = json.loads(response.body) + try: + response_body = json.loads(response.body.decode('utf-8')) + except (TypeError, ValueError): + LOGGER.warning('ERROR during "%s". Unable to load JSON: %s.', route, response.body.decode('utf-8')) + return False orders_dict = [Order(order, map_name=game.map_name, phase_type=game.phase_type) for order in response_body] all_orders_set = True |