Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Followup on PGoApi -- delaying errors, and reducing noise #2393

Merged
merged 1 commit into from
Aug 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30 SECS?!

Copy link
Contributor

@JSchwerberg JSchwerberg Aug 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're making the same mistake I did, @douglascamata -- it's 30 seconds if you get throttled 15 times in a row. Old behavior was to just exit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's a pause after 15 tries. This except is there to prevent the bot from crashing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then.... it's a trap!

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