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


Python Connector.send_echo方法代码示例

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


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

示例1: FURSBaseAPI

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import send_echo [as 别名]
class FURSBaseAPI():
    def __init__(self, p12_path, p12_password, production=True, request_timeout=2.0):
        self.connector = Connector(p12_path=p12_path,
                                   p12_password=p12_password,
                                   production=production,
                                   request_timeout=request_timeout)

    def is_server_accessible(self):
        """
        Check if FURS server is accessible. Will return False if server responds with anything else
        than HTTP Code: 200 or if the request timeouts.

        :return: (boolean) True for ok, False if there was a problem accessing server.
        """
        try:
            return self.connector.send_echo().status_code == codes.ok
        except Timeout as e:
            return False

    def _send_request(self, path, data):
        """
        Sends request to the FURS Server and decodes response.

        :param path: (string) Server path
        :param data: (dict) Data to be sent
        :return: (dict) Received response

        :raises:
            ConnectionTimedOutException: If connection timed out
            ConnectionException: If FURS responded with status code different than 200
            FURSException: If server responded with error
        """
        try:
            response = self.connector.post(path=path, json=data)

            if response.status_code == codes.ok:
                # TODO - we should verify server signature!
                server_response = jws.get_unverified_claims(response.json()['token'])

                return self._check_for_errors(server_response)
            else:
                raise ConnectionException(code=response.status_code,
                                          message=response.text)

        except Timeout as e:
            raise ConnectionTimedOutException(e)

    def _check_for_errors(self, server_response):
        """
        Check if server response contains FURS Error message and raise FURSException if it does
        :param server_response: (dict) FURS Server response data
        :return: server_response: (dict) FURS Server response data

        :raises
            FURSException: If response contains error
        """
        if server_response[server_response.keys()[0]].get('Error', None):
            raise FURSException(code=server_response[server_response.keys()[0]]['Error']['ErrorCode'],
                                message=server_response[server_response.keys()[0]]['Error']['ErrorMessage'])

        return server_response

    def _sign(self, content, digest='SHA256'):
        pkey = self.connector.p12.get_privatekey()

        return crypto.sign(pkey=pkey, data=content, digest=digest)
开发者ID:rulameven,项目名称:python-furs-fiscal,代码行数:68,代码来源:base_api.py


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