Skip to content

Commit

Permalink
Merge pull request #6043 from davidakachaos/improve_hash_error
Browse files Browse the repository at this point in the history
Improved error when hash key is expired
  • Loading branch information
Jcolomar authored May 15, 2017
2 parents 0f26f06 + 682cce9 commit 1da9f62
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pgoapi.exceptions import (ServerSideRequestThrottlingException,
NotLoggedInException, ServerBusyOrOfflineException,
NoPlayerPositionSetException, HashingOfflineException,
UnexpectedResponseException)
UnexpectedResponseException, BadHashRequestException)
from pgoapi.pgoapi import PGoApi
from pgoapi.pgoapi import PGoApiRequest
from pgoapi.pgoapi import RpcApi
Expand All @@ -29,7 +29,8 @@ class ApiWrapper(PGoApi, object):
def __init__(self, config=None):
self.config = config
self.gen_device_id()

self.logger = logging.getLogger(__name__)

device_info = {
"device_id": ApiWrapper.DEVICE_ID,
"device_brand": 'Apple',
Expand Down Expand Up @@ -94,18 +95,25 @@ def create_request(self):
def login(self, provider, username, password):
# login needs base class "create_request"
self.useVanillaRequest = True

try:
PGoApi.set_authentication(
self,
provider,
username=username,
password=password
)
self,
provider,
username=username,
password=password
)
except:
raise
try:
response = PGoApi.app_simulation_login(self)
except BadHashRequestException:
self.logger.warning("You hashkey seems to have expired or is not accepted!")
self.logger.warning("Please set a valid hash key in your auth JSON file!")
exit(-3)
raise
except:
raise

response = PGoApi.app_simulation_login(self)
# cleanup code
self.useVanillaRequest = False
return response
Expand Down Expand Up @@ -158,7 +166,14 @@ def can_call(self):
return True

def _call(self):
return PGoApiRequest.call(self)
for _attempt in range(10):
try:
return PGoApiRequest.call(self)
except:
self.log.info('Request failed, retrying.')
sleep(1)
else:
break

def _pop_request_callers(self):
r = self.request_callers
Expand Down Expand Up @@ -210,7 +225,7 @@ def call(self, max_retry=15):
should_throttle_retry = False
should_unexpected_response_retry = False
hashing_offline = False

try:
result = self._call()
except ServerSideRequestThrottlingException:
Expand All @@ -221,7 +236,7 @@ def call(self, max_retry=15):
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)
Expand Down

0 comments on commit 1da9f62

Please sign in to comment.