Skip to content

Commit

Permalink
Catch UnexpectedResponseException and retry (#2407)
Browse files Browse the repository at this point in the history
* Catch UnexpectedResponseException and retry

* New func for UnexpectedResponse

* Fixed merge conflicts.
  • Loading branch information
JSchwerberg authored and douglascamata committed Aug 3, 2016
1 parent 1ca2fa5 commit 3ef3fc7
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import time

from pgoapi.exceptions import ServerSideRequestThrottlingException, NotLoggedInException, ServerBusyOrOfflineException, NoPlayerPositionSetException, EmptySubrequestChainException
from pgoapi.exceptions import (ServerSideRequestThrottlingException,
NotLoggedInException, ServerBusyOrOfflineException,
NoPlayerPositionSetException, EmptySubrequestChainException,
UnexpectedResponseException)
from pgoapi.pgoapi import PGoApi, PGoApiRequest, RpcApi
from pgoapi.protos.POGOProtos.Networking.Requests_pb2 import RequestType

Expand Down Expand Up @@ -92,23 +95,36 @@ def call(self, max_retry=15):
result = None
try_cnt = 0
throttling_retry = 0
unexpected_response_retry = 0
while True:
request_timestamp = self.throttle_sleep()
# self._call internally clear this field, so save it
self._req_method_list = [req_method for req_method in api_req_method_list]
try:
result = self._call()
should_retry = False
should_throttle_retry = False
should_unexpected_response_retry = False
except ServerSideRequestThrottlingException:
should_retry = True
should_throttle_retry = True
except UnexpectedResponseException:
should_unexpected_response_retry = True

if should_retry:
if should_throttle_retry:
throttling_retry += 1
if throttling_retry >= max_retry:
raise ServerSideRequestThrottlingException('Server throttled too many times')
sleep(1) # huge sleep ?
continue # skip response checking

if should_unexpected_response_retry:
unexpected_reponse_retry += 1
if unexpected_response_retry >= 5:
logger.log('Server is not responding correctly to our requests. Waiting for 30 seconds to reconnect.', 'red')
sleep(30)
else:
sleep(2)
continue

if not self.is_response_valid(result, request_callers):
try_cnt += 1
if try_cnt > 3:
Expand Down

1 comment on commit 3ef3fc7

@Kafkamorph
Copy link

Choose a reason for hiding this comment

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

120:
s/reponse/response

Please sign in to comment.