From 21e4f7fa8bf3691fc9a455c8f77f84056aed99c7 Mon Sep 17 00:00:00 2001 From: JSchwerberg Date: Tue, 2 Aug 2016 15:46:58 -0700 Subject: [PATCH 1/3] Catch UnexpectedResponseException and retry --- pokemongo_bot/api_wrapper.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/api_wrapper.py b/pokemongo_bot/api_wrapper.py index 0cb3f9c62f..8da20a95ba 100644 --- a/pokemongo_bot/api_wrapper.py +++ b/pokemongo_bot/api_wrapper.py @@ -1,6 +1,9 @@ import time -from pgoapi.exceptions import ServerSideRequestThrottlingException, NotLoggedInException, ServerBusyOrOfflineException, NoPlayerPositionSetException, EmptySubrequestChainException +from pgoapi.exceptions import (ServerSideRequestThrottlingException, + NotLoggedInException, ServerBusyOrOfflineException, + NoPlayerPositionSetException, EmptySubrequestChainException, + UnexpectedResponseException) from pgoapi.pgoapi import PGoApi, PGoApiRequest, RpcApi from pgoapi.protos.POGOProtos.Networking.Requests_pb2 import RequestType @@ -99,7 +102,7 @@ def call(self, max_retry=5): try: result = self._call() should_retry = False - except ServerSideRequestThrottlingException: + except (ServerSideRequestThrottlingException, UnexpectedResponseException): should_retry = True if should_retry: From 0ca636084fdd74a5932924710b1df2ba5deaf4c0 Mon Sep 17 00:00:00 2001 From: JSchwerberg Date: Tue, 2 Aug 2016 15:58:38 -0700 Subject: [PATCH 2/3] New func for UnexpectedResponse --- pokemongo_bot/api_wrapper.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pokemongo_bot/api_wrapper.py b/pokemongo_bot/api_wrapper.py index 8da20a95ba..276140359c 100644 --- a/pokemongo_bot/api_wrapper.py +++ b/pokemongo_bot/api_wrapper.py @@ -95,17 +95,21 @@ def call(self, max_retry=5): result = None try_cnt = 0 throttling_retry = 0 + unexpected_response_retry = 0 while True: request_timestamp = self.throttle_sleep() # self._call internally clear this field, so save it self._req_method_list = [req_method for req_method in api_req_method_list] try: result = self._call() - should_retry = False - except (ServerSideRequestThrottlingException, UnexpectedResponseException): - should_retry = True - - if should_retry: + should_throttle_retry = False + should_unexpected_response_retry = False + except ServerSideRequestThrottlingException: + should_throttle_retry = True + except UnexpectedResponseException: + should_unexpected_response_retry = True + + if should_throttle_retry: throttling_retry += 1 logger.log("Server is throttling, let's slow down a bit") if throttling_retry >= max_retry: @@ -113,6 +117,16 @@ def call(self, max_retry=5): sleep(1) # huge sleep ? continue # skip response checking + if should_unexpected_response_retry: + unexpected_reponse_retry += 1 + if unexpected_response_retry >= 5: + logger.log('Server is not responding correctly to our requests. Waiting for 30 seconds to reconnect.', 'red') + sleep(30) + else: + sleep(2) + continue + + if not self.is_response_valid(result, request_callers): try_cnt += 1 logger.log('Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry), 'red') From cac41fa078102ddbc2ca027dcc414d34c4d67d58 Mon Sep 17 00:00:00 2001 From: Junaos Date: Tue, 2 Aug 2016 19:50:46 -0400 Subject: [PATCH 3/3] Fixed merge conflicts. --- pokemongo_bot/api_wrapper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pokemongo_bot/api_wrapper.py b/pokemongo_bot/api_wrapper.py index 95b544e79d..a3f70aed1f 100644 --- a/pokemongo_bot/api_wrapper.py +++ b/pokemongo_bot/api_wrapper.py @@ -125,7 +125,6 @@ def call(self, max_retry=15): sleep(2) continue - if not self.is_response_valid(result, request_callers): try_cnt += 1 if try_cnt > 3: