2

We are currently creating Dataproc clusters using below sample code,

from google.cloud import dataproc_v1

def sample_create_cluster():
    # Create a client
    client = dataproc_v1.ClusterControllerClient()

    # Initialize request argument(s)
    cluster = dataproc_v1.Cluster()
    cluster.project_id = "project_id_value"
    cluster.cluster_name = "cluster_name_value"

    request = dataproc_v1.CreateClusterRequest(
        project_id="project_id_value",
        region="region_value",
        cluster=cluster,
    )

    # Make the request
    operation = client.create_cluster(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

But incase any wrong input is sent through input payload, then I am getting errors in the html format like below, (in this case, I passed a wrong disk as pd-unknown just to show an error example)

<!doctype html>
<html lang=en>
<title>406 Not Acceptable</title>
<h1>Not Acceptable</h1>
<p>If provided, master boot disk type must be one of [pd-standard, pd-ssd, pd-balanced], but was &#39;pd-unknown&#39;</p>

This error looks a bit clumsy, is there any way we can capture the error code and error message in human readable format. Instead of html format.

I verified the library as well but I found nothing related to the error codes and status message. Any suggestion/message would help me.

  • Have you tried printing `operation` instead of `operation.result()`? – Dagang Sep 07 '22 at 05:31
  • @Dagang, yes I tried it printed the object type as google.api_core.operation and I searched in below link and found nothing related to capturing error codes and error messages. "https://googleapis.dev/python/google-api-core/1.14.0/_modules/google/api_core/operation.html" – ash_ketchum12 Sep 07 '22 at 08:38
  • What's the type of `operation.result()`? – Dagang Sep 07 '22 at 13:44

0 Answers0