Skip to content

Commit

Permalink
Fix issue that made TooManyLoginAttempts to never be raised (RocketMa…
Browse files Browse the repository at this point in the history
…p#1815)

* Fix issue that made TooManyLoginAttempts to never be raised

Also, make the code follow what --login-retries really means

* Improve the while loop code

* Rename i to num_tries
  • Loading branch information
onilton authored and sebastienvercammen committed Feb 11, 2017
1 parent 6877c41 commit e45c4a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 16 additions & 11 deletions pogom/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def check_login(args, account, api, position, proxy_url):
return

# Try to login. Repeat a few times, but don't get stuck here.
i = 0
while i < args.login_retries:
num_tries = 0
# One initial try + login_retries.
while num_tries < (args.login_retries + 1):
try:
if proxy_url:
api.set_authentication(
Expand All @@ -42,15 +43,19 @@ def check_login(args, account, api, position, proxy_url):
password=account['password'])
break
except AuthException:
if i >= args.login_retries:
raise TooManyLoginAttempts('Exceeded login attempts.')
else:
i += 1
log.error(
('Failed to login to Pokemon Go with account %s. ' +
'Trying again in %g seconds.'),
account['username'], args.login_delay)
time.sleep(args.login_delay)
num_tries += 1
log.error(
('Failed to login to Pokemon Go with account %s. ' +
'Trying again in %g seconds.'),
account['username'], args.login_delay)
time.sleep(args.login_delay)

if num_tries > args.login_retries:
log.error(
('Failed to login to Pokemon Go with account %s in ' +
'%d tries. Giving up.'),
account['username'], num_tries)
raise TooManyLoginAttempts('Exceeded login attempts.')

log.debug('Login for account %s successful.', account['username'])
time.sleep(20)
Expand Down
4 changes: 2 additions & 2 deletions pogom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def get_args():
help='Time delay between each login attempt.',
type=float, default=6)
parser.add_argument('-lr', '--login-retries',
help=('Number of login attempts before refreshing ' +
'a thread.'),
help=('Number of times to retry the login before ' +
'refreshing a thread.'),
type=int, default=3)
parser.add_argument('-mf', '--max-failures',
help=('Maximum number of failures to parse ' +
Expand Down

0 comments on commit e45c4a6

Please sign in to comment.