From 5a13eaa3a7392e188d0f7e0094d0c014d77c4c98 Mon Sep 17 00:00:00 2001 From: MerlionRock Date: Thu, 11 May 2017 12:27:59 +0800 Subject: [PATCH 1/2] Exceptions Added Common Exceptions like Hashing Server Busy added --- pokemongo_bot/__init__.py | 9 +++++++-- pokemongo_bot/api_wrapper.py | 13 ++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index fd5c19ac7b..bc18ef0e7e 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -42,7 +42,7 @@ from .inventory import init_inventory, player from sys import platform as _platform from pgoapi.protos.pogoprotos.enums import badge_type_pb2 -from pgoapi.exceptions import AuthException, NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException, NoPlayerPositionSetException +from pgoapi.exceptions import AuthException, NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException, NoPlayerPositionSetException, HashingOfflineException from pgoapi.hash_server import HashServer @@ -1541,7 +1541,12 @@ def heartbeat(self): request = self.api.create_request() request.get_player() request.check_awarded_badges() - responses = request.call() + try: + responses = request.call() + except NotLoggedInException: + self.logger.warning('Unable to login, retying') + except: + self.logger.warning('Error occured in heatbeat, retying') if responses['responses']['GET_PLAYER']['success'] == True: # we get the player_data anyway, might as well store it diff --git a/pokemongo_bot/api_wrapper.py b/pokemongo_bot/api_wrapper.py index c0db5b9e12..c953373d9a 100644 --- a/pokemongo_bot/api_wrapper.py +++ b/pokemongo_bot/api_wrapper.py @@ -8,7 +8,7 @@ import sys from pgoapi.exceptions import (ServerSideRequestThrottlingException, NotLoggedInException, ServerBusyOrOfflineException, - NoPlayerPositionSetException, + NoPlayerPositionSetException, HashingOfflineException, UnexpectedResponseException) from pgoapi.pgoapi import PGoApi from pgoapi.pgoapi import PGoApiRequest @@ -209,12 +209,23 @@ def call(self, max_retry=15): self._req_method_list = [req_method for req_method in api_req_method_list] should_throttle_retry = False should_unexpected_response_retry = False + hashing_offline = False + try: result = self._call() except ServerSideRequestThrottlingException: should_throttle_retry = True + except HashingOfflineException: + hashing_offline = True except UnexpectedResponseException: should_unexpected_response_retry = True + except: + should_unexpected_response_retry = True + + if hashing_offline: + self.logger.warning('Hashing server issue, retrying in 5 Secs...') + sleep(5) + continue if should_throttle_retry: throttling_retry += 1 From 4169ee57df39ee2a9ce74009f1bace6cad9ca832 Mon Sep 17 00:00:00 2001 From: MerlionRock Date: Thu, 11 May 2017 12:28:52 +0800 Subject: [PATCH 2/2] Exceptions Added --- pokemongo_bot/event_handlers/social_handler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/event_handlers/social_handler.py b/pokemongo_bot/event_handlers/social_handler.py index 59fbf48f90..0d06d4ced3 100644 --- a/pokemongo_bot/event_handlers/social_handler.py +++ b/pokemongo_bot/event_handlers/social_handler.py @@ -83,7 +83,10 @@ def initialize(self): return def run(self): - self._mqttc.connect("broker.pikabot.org", 1883, 20) + try: + self._mqttc.connect("broker.pikabot.org", 1883, 20) + except: + print('Error occured in social handler') while True: try: self._mqttc.loop_forever(timeout=30.0, max_packets=100, retry_first_connection=False)