コード例 #1
0
    def _handle_session_response(response):
        """Internal helper for handling API responses from the server.
        Raises the appropriate exceptions when necessary; otherwise, returns the
        response.
        """

        if not str(response.status_code).startswith('2'):
            raise BinanceChainRPCException(response)
        try:
            res = response.json()

            if 'code' in res and res['code'] != "200000":
                raise BinanceChainRPCException(response)

            if 'success' in res and not res['success']:
                raise BinanceChainRPCException(response)

            # by default return full response
            # if it's a normal response we have a data attribute, return that
            if 'result' in res:
                res = res['result']
            return res
        except ValueError:
            raise BinanceChainRequestException('Invalid Response: %s' %
                                               response.text)
コード例 #2
0
    async def _handle_response(self, response):
        """Internal helper for handling API responses from the Binance server.
        Raises the appropriate exceptions when necessary; otherwise, returns the
        response.
        """
        if not str(response.status).startswith('2'):
            t = await response.text()
            ar = WrappedAsyncResponse(t)
            raise BinanceChainAPIException(ar, response.status)
        try:
            res = await response.json()

            if 'code' in res and res['code'] not in [0, "200000"]:
                raise BinanceChainAPIException(response, response.status)

            if 'success' in res and not res['success']:
                raise BinanceChainAPIException(response, response.status)

            # by default return full response
            # if it's a normal response we have a data attribute, return that
            if 'data' in res:
                res = res['data']
            return res
        except ValueError:
            raise BinanceChainRequestException('Invalid Response: %s' %
                                               await response.text())
コード例 #3
0
    def _handle_response(response):
        """Internal helper for handling API responses from the server.
        Raises the appropriate exceptions when necessary; otherwise, returns the
        response.
        """

        try:
            res = response.json()

            if 'error' in res and res['error']:
                raise BinanceChainRPCException(response)

            # by default return full response
            # if it's a normal response we have a data attribute, return that
            if 'result' in res:
                res = res['result']
            return res
        except ValueError:
            raise BinanceChainRequestException('Invalid Response: %s' %
                                               response.text)
コード例 #4
0
    def _handle_response(response):
        """Internal helper for handling API responses from the server.
        Raises the appropriate exceptions when necessary; otherwise, returns the
        response.
        """
        if not str(response.status_code).startswith('2'):
            raise BinanceChainAPIException(response, response.status_code)
        try:
            res = response.json()

            if 'code' in res and res['code'] != "200000":
                raise BinanceChainAPIException(response, response.status_code)

            if 'message' in res:
                raise BinanceChainAPIException(response, response.status_code)

            return res
        except ValueError:
            raise BinanceChainRequestException('Invalid Response: %s' %
                                               response.text)