Skip to content

Commit 57cbe4e

Browse files
committed
Handle ThrottlingException
1 parent 8e2abc4 commit 57cbe4e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pokemongo_bot/api_wrapper.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22

3-
from pgoapi.exceptions import NotLoggedInException, ServerBusyOrOfflineException, NoPlayerPositionSetException, EmptySubrequestChainException
3+
from pgoapi.exceptions import ServerSideRequestThrottlingException, NotLoggedInException, ServerBusyOrOfflineException, NoPlayerPositionSetException, EmptySubrequestChainException
44
from pgoapi.pgoapi import PGoApi, PGoApiRequest, RpcApi
55
from pgoapi.protos.POGOProtos.Networking.Requests_pb2 import RequestType
66

@@ -88,12 +88,25 @@ def call(self, max_retry=5):
8888
api_req_method_list = self._req_method_list
8989
result = None
9090
try_cnt = 0
91-
91+
throttling_retry = 0
9292
while True:
9393
request_timestamp = self.throttle_sleep()
9494
# self._call internally clear this field, so save it
9595
self._req_method_list = [req_method for req_method in api_req_method_list]
96-
result = self._call()
96+
try:
97+
result = self._call()
98+
should_retry = False
99+
except ServerSideRequestThrottlingException:
100+
should_retry = True
101+
102+
if should_retry:
103+
throttling_retry += 1
104+
logger.log("Server is throttling, let's slow down a bit")
105+
if throttling_retry >= max_retry:
106+
raise ServerSideRequestThrottlingException('Server throttled too many times')
107+
sleep(5) # huge sleep ?
108+
continue # skip response checking
109+
97110
if not self.is_response_valid(result, request_callers):
98111
try_cnt += 1
99112
logger.log('Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry), 'red')

0 commit comments

Comments
 (0)