Skip to content

Commit

Permalink
delaying errors, and reducing noise (#2393)
Browse files Browse the repository at this point in the history
  • Loading branch information
DayBr3ak authored and douglascamata committed Aug 2, 2016
1 parent d27a566 commit 75f9c4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import time
from datetime import timedelta
from getpass import getpass
from pgoapi.exceptions import NotLoggedInException
from pgoapi.exceptions import NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException
from geopy.exc import GeocoderQuotaExceeded

from pokemongo_bot import PokemonGoBot, TreeConfigBuilder
Expand Down Expand Up @@ -74,9 +74,12 @@ def main():
logger.log('Exiting PokemonGo Bot', 'red')
finished = True
report_summary(bot)
except NotLoggedInException:
except (NotLoggedInException, ServerBusyOrOfflineException):
logger.log('[x] Error while connecting to the server, please wait %s minutes' % config.reconnecting_timeout, 'red')
time.sleep(config.reconnecting_timeout * 60)
except ServerSideRequestThrottlingException:
logger.log('Server is throttling, reconnecting in 30sec')
time.sleep(30)
except GeocoderQuotaExceeded:
logger.log('[x] The given maps api key has gone over the requests limit.', 'red')
finished = True
Expand Down
6 changes: 3 additions & 3 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def is_response_valid(self, result, request_callers):

return True

def call(self, max_retry=5):
def call(self, max_retry=15):
request_callers = self._pop_request_callers()
if not self.can_call():
return False # currently this is never ran, exceptions are raised before
Expand All @@ -104,15 +104,15 @@ def call(self, max_retry=5):

if should_retry:
throttling_retry += 1
logger.log("Server is throttling, let's slow down a bit")
if throttling_retry >= max_retry:
raise ServerSideRequestThrottlingException('Server throttled too many times')
sleep(1) # huge sleep ?
continue # skip response checking

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')
if try_cnt > 3:
logger.log('Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry), 'red')
if try_cnt >= max_retry:
raise ServerBusyOrOfflineException()
sleep(1)
Expand Down

0 comments on commit 75f9c4b

Please sign in to comment.