当前位置: 首页>>代码示例>>Python>>正文


Python RpcApi._session方法代码示例

本文整理汇总了Python中pgoapi.rpc_api.RpcApi._session方法的典型用法代码示例。如果您正苦于以下问题:Python RpcApi._session方法的具体用法?Python RpcApi._session怎么用?Python RpcApi._session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pgoapi.rpc_api.RpcApi的用法示例。


在下文中一共展示了RpcApi._session方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: call

# 需要导入模块: from pgoapi.rpc_api import RpcApi [as 别名]
# 或者: from pgoapi.rpc_api.RpcApi import _session [as 别名]
    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
开发者ID:Devilkk,项目名称:pgoapi,代码行数:52,代码来源:pgoapi.py

示例2: call

# 需要导入模块: from pgoapi.rpc_api import RpcApi [as 别名]
# 或者: from pgoapi.rpc_api.RpcApi import _session [as 别名]
    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
开发者ID:Zoruk,项目名称:pgoapi,代码行数:66,代码来源:pgoapi.py


注:本文中的pgoapi.rpc_api.RpcApi._session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。