def call(self, method, *args, **kwargs): """ Creates the JSON-RPC request string, calls the HTTP server, converts JSON-RPC response string to python and returns the result. :param method: Name of the method which will be called on the HTTP server. Or a list with RPC-Request-Dictionaries. Syntax:: "<MethodName>" or [<JsonRpcRequestDict>, ...] RPC-Request-Dictionaries will be made with the function *rpcrequest.create_request_dict()*. """ # Create JSON-RPC-request if isinstance(method, basestring): request_json = rpcrequest.create_request_json(method, *args, **kwargs) else: assert not args and not kwargs request_json = rpcjson.dumps(method) # Call the HTTP-JSON-RPC server response_json = http_request( url = self.url, json_string = request_json, username = self.username, password = self.password, timeout = self.timeout, additional_headers = self.additional_headers, content_type = self.content_type, cookies = self.cookies, gzipped = self.gzipped, ssl_context = self.ssl_context, debug = self.debug ) if not response_json: return # Convert JSON-RPC-response to python-object response = rpcresponse.parse_response_json(response_json) if isinstance(response, rpcresponse.Response): if response.error: # Raise error if response.error.code in rpcerror.jsonrpcerrors: raise rpcerror.jsonrpcerrors[response.error.code]( message = response.error.message, data = response.error.data ) else: raise rpcerror.JsonRpcError( message = response.error.message, data = response.error.data, code = response.error.code ) else: # Return result return response.result elif isinstance(response, list): # Bei Listen wird keine Fehlerauswerung gemacht return response
def call(self, method, *args, **kwargs): """ Creates the JSON-RPC request string, calls the HTTP server, converts JSON-RPC response string to python and returns the result. :param method: Name of the method which will be called on the HTTP server. Or a list with RPC-Request-Dictionaries. Syntax:: "<MethodName>" or [<JsonRpcRequestDict>, ...] RPC-Request-Dictionaries will be made with the function *rpcrequest.create_request_dict()*. """ # Create JSON-RPC-request if isinstance(method, string_types): request_json = rpcrequest.create_request_json(method, *args, **kwargs) else: assert not args and not kwargs request_json = rpcjson.dumps(method) # Call the HTTP-JSON-RPC server response_json = http_request( url = self.url, json_string = request_json, username = self.username, password = self.password, timeout = self.timeout, additional_headers = self.additional_headers, content_type = self.content_type, cookies = self.cookies, gzipped = self.gzipped, ssl_context = self.ssl_context, debug = self.debug ) if not response_json: return # Convert JSON-RPC-response to python-object response = rpcresponse.parse_response_json(response_json) if isinstance(response, rpcresponse.Response): if response.error: # Raise error if response.error.code in rpcerror.jsonrpcerrors: raise rpcerror.jsonrpcerrors[response.error.code]( message = response.error.message, data = response.error.data ) else: raise rpcerror.JsonRpcError( message = response.error.message, data = response.error.data, code = response.error.code ) else: # Return result return response.result elif isinstance(response, list): # Bei Listen wird keine Fehlerauswerung gemacht return response
def call(self, method, *args, **kwargs): """ Creates the JSON-RPC request string, calls the HTTP server, converts JSON-RPC response string to python and returns the result. :param method: Name of the method which will be called on the HTTP server. Or a list with RPC-Request-Dictionaries. Syntax:: "<MethodName>" or [<JsonRpcRequestDict>, ...] RPC-Request-Dictionaries will be made with the function *rpcrequest.create_request_dict()*. """ # Create JSON-RPC-request if isinstance(method, basestring): request_json = rpcrequest.create_request_json(method, *args, **kwargs) else: request_json = json.dumps(method) assert not args and not kwargs # Call the HTTP-JSON-RPC server response_json = http_request( url = self.url, json_string = request_json, username = self.username, password = self.password, cookies = self.cookies ) # Convert JSON-RPC-response to python-object response = rpcresponse.parse_response_json(response_json) if response.error: # Raise error raise rpcerror.jsonrpcerrors[response.error.code]( message = response.error.message, data = response.error.data ) else: # Return result return response.result
def call(self, method, *args, **kwargs): """ Creates the JSON-RPC request string, calls the HTTP server, converts JSON-RPC response string to python and returns the result. :param method: Name of the method which will be called on the HTTP server. Or a list with RPC-Request-Dictionaries. Syntax:: "<MethodName>" or [<JsonRpcRequestDict>, ...] RPC-Request-Dictionaries will be made with the function *rpcrequest.create_request_dict()*. """ # Create JSON-RPC-request if isinstance(method, basestring): request_json = rpcrequest.create_request_json(method, *args, **kwargs) else: request_json = json.dumps(method) assert not args and not kwargs # Call the HTTP-JSON-RPC server response_json = http_request( url = self.url, json_string = request_json, username = self.username, password = self.password ) # Convert JSON-RPC-response to python-object response = rpcresponse.parse_response_json(response_json) if response.error: # Raise error raise rpcerror.jsonrpcerrors[response.error.code]( message = response.error.message, data = response.error.data ) else: # Return result return response.result