neojsonrpc/client.py
def _call(self, method, params=None, request_id=None):
        """ Calls the JSON-RPC endpoint. """
        params = params or []

        # Determines which 'id' value to use and increment the counter associated with the current
        # client instance if applicable.
        rid = request_id or self._id_counter
        if request_id is None:
            self._id_counter += 1

        # Prepares the payload and the headers that will be used to forge the request.
        payload = {'jsonrpc': '2.0', 'method': method, 'params': params, 'id': rid}
        headers = {'Content-Type': 'application/json'}
        scheme = 'https' if self.tls else 'http'
        url = '{}://{}:{}'.format(scheme, self.host, self.port)

        # Calls the JSON-RPC endpoint!
        try:
            response = self.session.post(url, headers=headers, data=json.dumps(payload))
            response.raise_for_status()
        except HTTPError:
            raise TransportError(
                'Got unsuccessful response from server (status code: {})'.format(
                    response.status_code),
                response=response)

        # Ensures the response body can be deserialized to JSON.
        try:
            response_data = response.json()
        except ValueError as e:
            raise ProtocolError(
                'Unable to deserialize response body: {}'.format(e), response=response)

        # Properly handles potential errors.
        if response_data.get('error'):
            code = response_data['error'].get('code', '')
            message = response_data['error'].get('message', '')
            raise ProtocolError(
                'Error[{}] {}'.format(code, message), response=response, data=response_data)
        elif 'result' not in response_data:
            raise ProtocolError(
                'Response is empty (result field is missing)', response=response,
                data=response_data)

        return response_data['result']
def _call(self, method, params=None, request_id=None):
        params = params or []

        # Determines which 'id' value to use and increment the counter associated with the current
        # client instance if applicable.
        rid = request_id or self._id_counter
        if request_id is None:
            self._id_counter += 1

        # Prepares the payload and the headers that will be used to forge the request.
        payload = {'jsonrpc': '2.0', 'method': method, 'params': params, 'id': rid}
        headers = {'Content-Type': 'application/json'}
        scheme = 'https' if self.tls else 'http'
        url = '{}://{}:{}'.format(scheme, self.host, self.port)

        # Calls the JSON-RPC endpoint!
        try:
            response = self.session.post(url, headers=headers, data=json.dumps(payload))
            response.raise_for_status()
        except HTTPError:
            raise TransportError(
                'Got unsuccessful response from server (status code: {})'.format(
                    response.status_code),
                response=response)

        # Ensures the response body can be deserialized to JSON.
        try:
            response_data = response.json()
        except ValueError as e:
            raise ProtocolError(
                'Unable to deserialize response body: {}'.format(e), response=response)

        # Properly handles potential errors.
        if response_data.get('error'):
            code = response_data['error'].get('code', '')
            message = response_data['error'].get('message', '')
            raise ProtocolError(
                'Error[{}] {}'.format(code, message), response=response, data=response_data)
        elif 'result' not in response_data:
            raise ProtocolError(
                'Response is empty (result field is missing)', response=response,
                data=response_data)

        return response_data['result']
def _call ( self , method , params = None , request_id = None ) : params = params or [ ] # Determines which 'id' value to use and increment the counter associated with the current # client instance if applicable. rid = request_id or self . _id_counter if request_id is None : self . _id_counter += 1 # Prepares the payload and the headers that will be used to forge the request. payload = { 'jsonrpc' : '2.0' , 'method' : method , 'params' : params , 'id' : rid } headers = { 'Content-Type' : 'application/json' } scheme = 'https' if self . tls else 'http' url = '{}://{}:{}' . format ( scheme , self . host , self . port ) # Calls the JSON-RPC endpoint! try : response = self . session . post ( url , headers = headers , data = json . dumps ( payload ) ) response . raise_for_status ( ) except HTTPError : raise TransportError ( 'Got unsuccessful response from server (status code: {})' . format ( response . status_code ) , response = response ) # Ensures the response body can be deserialized to JSON. try : response_data = response . json ( ) except ValueError as e : raise ProtocolError ( 'Unable to deserialize response body: {}' . format ( e ) , response = response ) # Properly handles potential errors. if response_data . get ( 'error' ) : code = response_data [ 'error' ] . get ( 'code' , '' ) message = response_data [ 'error' ] . get ( 'message' , '' ) raise ProtocolError ( 'Error[{}] {}' . format ( code , message ) , response = response , data = response_data ) elif 'result' not in response_data : raise ProtocolError ( 'Response is empty (result field is missing)' , response = response , data = response_data ) return response_data [ 'result' ]
Calls the JSON-RPC endpoint.
Calls the JSON - RPC endpoint .