def send_request(client: ExonumClient, endpoint: str, data: bytes) -> None: """This function encodes request from bytes to JSON, sends it to the Exonum and waits.""" # Post the request to Exonum: supervisor_private_api = client.service_private_api("supervisor") response = supervisor_private_api.post_service(endpoint, data, data_format="binary") if response.status_code != 200: error_msg = f"Error occurred during the request to the '{endpoint}' endpoint: {response.content!r}" raise RuntimeError(error_msg) # Wait for 10 seconds. # TODO: currently due to a bug in Exonum it takes up to 10 seconds to update the dispatcher info: time.sleep(5)
def send_request(client: ExonumClient, endpoint: str, data: bytes) -> None: """This function encodes request from bytes to JSON, sends it to the Exonum and waits.""" # Convert the request to a hexadecimal string: hex_request = data.hex() # Convert the request to a JSON: json_request = json.dumps(hex_request) # Post the request to Exonum: supervisor_private_api = client.service_private_api("supervisor") response = supervisor_private_api.post_service(endpoint, json_request) if response.status_code != 200: error_msg = f"Error occurred during the request to the '{endpoint}' endpoint: {response.content!r}" raise RuntimeError(error_msg) # Wait for 10 seconds. # TODO: currently due to a bug in Exonum it takes up to 10 seconds to update the dispatcher info: time.sleep(10)