gcp datacatalog_v1beta1 create taxonomy and policy tags failed

1.1k Views Asked by At

I am trying to use Python Client for Google Cloud Data Catalog API beta 1 to create taxonomy and policy tags. here is my code:

from google.cloud.datacatalog_v1beta1 import PolicyTagManagerClient, enums, types
from google.oauth2 import service_account


key_path = "./xxxxx.json"
credentials = service_account.Credentials.from_service_account_file(
    key_path,
    scopes=["https://www.googleapis.com/auth/cloud-platform"],
)

client = PolicyTagManagerClient(credentials=credentials)
resource_name = '//bigquery.googleapis.com/projects/{}/locations/us/taxonomies/{}'.format('3xxxxxxxx58','50xxxxxxxxx14')
taxonomy = client.get_taxonomy(resource_name) 
print(taxonomy)

pt_taxonomy = types.Taxonomy()
pt_taxonomy.display_name = 'PHI'
response = client.create_taxonomy(parent=<project_id>, taxonomy=pt_taxonomy)

I get following error for get_taxonomy()

google.api_core.exceptions.MethodNotImplemented: 501 Operation is not implemented, or supported, or enabled.

and for create_taxonomy() I got:

"Received http2 header with status: 404","grpc_status":1,"value":"404"}"

any idea? Thank you for your help!

BTW google api call does work, it returns 200 with following example.

enter image description here

So I changed my code to:

pt_taxonomy1 = types.Taxonomy()
pt_taxonomy1.display_name = 'PHI1'

response = client.create_taxonomy('projects/39xxxxx/locations/us', pt_taxonomy1)

still same 501 error

2

There are 2 best solutions below

0
Mahboob On

From the docs click here, noticed that the error message NOT_IMPLEMENTED (501) has been described here. I guess you need to use parameters on client.get_taxonomy() like project_id, region and cluster as resources have these parameters. You can look in to the article click here for authorization scope and also click here for API method.

0
Ricardo Mendes On

@hdu, I filed a bug describing the 501 error in the client library repository: https://github.com/googleapis/python-datacatalog/issues/33. [EDITED] This bug has been fixed.

In spite of the 501 error, I believe there's another minor issue in your script:

resource_name = '//bigquery.googleapis.com/projects/{}/locations/us/taxonomies/{}'.format('3xxxxxxxx58','50xxxxxxxxx14') taxonomy = client.get_taxonomy(resource_name)

GET Taxonomy expects the resource name of the requested taxonomy as an argument, formatted as projects/{project_id}/locations/{location_id}/taxonomies/{taxonomies_id} (source).