本文整理匯總了Python中pgoapi.rpc_api.RpcApi類的典型用法代碼示例。如果您正苦於以下問題:Python RpcApi類的具體用法?Python RpcApi怎麽用?Python RpcApi使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RpcApi類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: call
def call(self):
if not self._req_method_list:
return False
if self._auth_provider is None or not self._auth_provider.is_login():
self.log.info('Not logged in')
return False
player_position = self.get_position()
request = RpcApi(self._auth_provider)
if self._api_endpoint:
api_endpoint = self._api_endpoint
else:
api_endpoint = self.API_ENTRY
self.log.info('Execution of RPC')
response = None
try:
response = request.request(api_endpoint, self._req_method_list, player_position)
except ServerBusyOrOfflineException as e:
self.log.info('Server seems to be busy or offline - try again!')
# cleanup after call execution
self.log.info('Cleanup of request!')
self._req_method_list = []
return response
示例2: call
def call(self):
if not self._req_method_list:
raise EmptySubrequestChainException()
if (self._position_lat is None) or (self._position_lng is None) or (self._position_alt is None):
raise NoPlayerPositionSetException()
if self._auth_provider is None or not self._auth_provider.is_login():
self.log.info('Not logged in')
return NotLoggedInException()
request = RpcApi(self._auth_provider)
self.log.info('Execution of RPC')
response = None
try:
response = request.request(self._api_endpoint, self._req_method_list, self.get_position())
except ServerBusyOrOfflineException as e:
self.log.info('Server seems to be busy or offline - try again!')
# cleanup after call execution
self.log.info('Cleanup of request!')
self._req_method_list = []
return response
示例3: call
def call(self, use_dict = True):
if (self._position_lat is None) or (self._position_lng is None):
raise NoPlayerPositionSetException
if self._auth_provider is None or not self._auth_provider.is_login():
self.log.info('Not logged in')
raise NotLoggedInException
request = RpcApi(self._auth_provider, self.device_info)
request._session = self.__parent__._session
hash_server_token = self.__parent__.get_hash_server_token()
request.activate_hash_server(hash_server_token)
response = None
execute = True
while execute:
execute = False
try:
response = request.request(self._api_endpoint, self._req_method_list, self._req_platform_list, self.get_position(), use_dict)
except AuthTokenExpiredException as e:
"""
This exception only occures if the OAUTH service provider (google/ptc) didn't send any expiration date
so that we are assuming, that the access_token is always valid until the API server states differently.
"""
try:
self.log.info('Access Token rejected! Requesting new one...')
self._auth_provider.get_access_token(force_refresh=True)
except Exception as e:
error = 'Reauthentication failed: {}'.format(e)
self.log.error(error)
raise NotLoggedInException(error)
request.request_proto = None # reset request and rebuild
execute = True # reexecute the call
except ServerApiEndpointRedirectException as e:
self.log.info('API Endpoint redirect... re-execution of call')
new_api_endpoint = e.get_redirected_endpoint()
self._api_endpoint = parse_api_endpoint(new_api_endpoint)
self.__parent__.set_api_endpoint(self._api_endpoint)
execute = True # reexecute the call
# cleanup after call execution
self._req_method_list = []
return response
示例4: call
def call(self):
if not self._req_method_list:
raise EmptySubrequestChainException()
if (self._position_lat is None) or (self._position_lng is None) or (self._position_alt is None):
raise NoPlayerPositionSetException()
if self._auth_provider is None or not self._auth_provider.is_login():
self.log.info('Not logged in')
return NotLoggedInException()
request = RpcApi(self._auth_provider)
request._session = self.__parent__._session
lib_path = self.__parent__.get_signature_lib()
if lib_path is not None:
request.activate_signature(lib_path)
self.log.info('Execution of RPC')
response = None
execute = True
while execute:
execute = False
try:
response = request.request(self._api_endpoint, self._req_method_list, self.get_position())
except AuthTokenExpiredException as e:
"""
This exception only occures if the OAUTH service provider (google/ptc) didn't send any expiration date
so that we are assuming, that the access_token is always valid until the API server states differently.
"""
try:
self.log.info('Access Token rejected! Requesting new one...')
self._auth_provider.get_access_token(force_refresh=True)
except:
error = 'Request for new Access Token failed! Logged out...'
self.log.error(error)
raise NotLoggedInException(error)
""" reexecute the call"""
execute = True
except ServerApiEndpointRedirectException as e:
self.log.info('API Endpoint redirect... re-execution of call')
new_api_endpoint = e.get_redirected_endpoint()
self._api_endpoint = parse_api_endpoint(new_api_endpoint)
self.__parent__.set_api_endpoint(self._api_endpoint)
""" reexecute the call"""
execute = True
except ServerBusyOrOfflineException as e:
""" no execute = True here, as API retries on HTTP level should be done on a lower level, e.g. in rpc_api """
self.log.info('Server seems to be busy or offline - try again!')
self.log.debug('ServerBusyOrOfflineException details: %s', e)
except UnexpectedResponseException as e:
self.log.error('Unexpected server response!')
raise
# cleanup after call execution
self.log.info('Cleanup of request!')
self._req_method_list = []
return response