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

Improved error when hash key is expired #6043

Merged
merged 1 commit into from
May 15, 2017
Merged
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
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