Error Python API GCP Data Catalog - Google Cloud Platform

Emilio

I'm getting an error trying of use the code of this link: Data Catalog Example. At the step 4, just copy pasting all the code provided, authenticating into my GCP Project and testing it.

Everything is ok until it start creating tag template fields...

tag_template = datacatalog_v1.types.TagTemplate()
tag_template.display_name = 'On-premises Tag Template'

tag_template.fields['source'].display_name = 'Source of the data asset'
tag_template.fields['source'].type.primitive_type = \
    datacatalog_v1.FieldType.PrimitiveType.STRING.value

it always crash with the same error.

Error Image

tag_template <proto.marshal.collections.maps.MapComposite object at 0x10fe23310>
Traceback (most recent call last):
  File "/Users/ac/Documents/DataCatalog/python_datacatalog/application/sample.py", line 149, in <module>
    tag_template.fields['source'].display_name = 'Source of the data asset'
  File "/Users/ac/Documents/DataCatalog/python_datacatalog/venv/lib/python3.8/site-packages/proto/marshal/collections/maps.py", line 56, in __getitem__
    raise KeyError(key)
KeyError: 'source'

Someone can help me sharing alternatives to do this?

Ricco D

The sample code on the Data Catalog Example is outdated. Did a few changes on the code starting at step 4 (where you are currently stuck). I encountered another error at the next line for primitive type.

# -------------------------------
# 4. Create a Tag Template.
# -------------------------------
tag_template = datacatalog_v1.types.TagTemplate()
tag_template.display_name = 'On-premises Tag Template'

tag_template.fields['source'] = datacatalog_v1.types.TagTemplateField() #creates key 'source'
tag_template.fields['source'].display_name = 'Source of the data asset'
tag_template.fields['source'].type_.primitive_type = datacatalog_v1.types.FieldType.PrimitiveType.STRING #from type -> type_, syntax for primitive type string
  • Fix is to create the key 'source' for TagTemplateField by adding tag_template.fields['source'] = datacatalog_v1.types.TagTemplateField()
  • Updated the syntax for "tag_template.type" and assigning primitive string value

If you proceed to step 5, an error will pop up KeyError: 'source'. If you did not encounter this then it is all good. But if ever you encounter it here is the code to fix that.

# -------------------------------
# 5. Attach a Tag to the custom Entry.
# -------------------------------
tag = datacatalog_v1.types.Tag()
tag.template = tag_template.name
tag.fields['source'] = datacatalog_v1.types.TagField() #creates key 'source'
tag.fields['source'].string_value = 'On-premises system name'

tag = datacatalog.create_tag(parent=entry.name, tag=tag)
print('Created tag: {}'.format(tag.name))
  • Fix is similar to step 4 which is to create the key 'source' this time for TagField by adding tag.fields['source'] = datacatalog_v1.types.TagField() #creates key 'source'

I ran the whole script from step 1 to 5.

Output of the script: enter image description here

Created tag template: enter image description here

Created tag: enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Propagating Error messages in Google Cloud Platform (GCP)

From Dev

Building Google Cloud Platform Data Catalog on unstructured data

From Dev

Google Cloud Platform - Datastore - Python ndb API

From Dev

GCP: Full backup of the database in the google cloud platform

From Dev

Google Cloud Platform (GCP) Ingress unhealthy backend

From Dev

GCP: Duplicate an existing project in Google Cloud Platform

From Dev

Google Play Security alert about Google Cloud Platform (GCP) API keys

From Dev

While creating API Gateway in google cloud platform throwing unreachable error

From Dev

Accessing GCP Memorystore from Google Cloud Platform Cloud Shell

From Dev

Google Cloud Platform (GCP) Cloud Shell "Boost" feature missing

From Dev

GCP AI Platform cannot read .SAV file stored in Google Cloud Storage (Python)

From Dev

Google Cloud Platform Data Display

From Dev

Google Cloud Platform SDK with Python

From Dev

Is there a way to change a google cloud platform project to other GCP account?

From Dev

Google Cloud Platform (GCP): How to give additional roles to service account?

From Dev

How to monitor Google Cloud Platform (GCP) costs on an hourly basis?

From Dev

Google cloud platform | 100% API error rate when using google translation API

From Dev

The Python script for updating rules in the Cloud Armor in Google Cloud Platform by REST API

From Dev

Using Google Cloud Platform for scheduled recurring API data pull that then loads the data to BigQuery

From Dev

Google cloud platform support plan from API

From Dev

GCP python API. Accessing getiampolicy for gcp cloud sql instance

From Dev

Google cloud AI platform error in executing job

From Dev

Using Error report of Google Cloud Platform with ExpressJS

From Dev

Docker image run error on Google Cloud Platform

From Dev

GCP Cloud Functions for python output data file

From Dev

Error installing fbprophet on Google Cloud Platform AI Platform

From Dev

How to fetch data from Google Cloud Platform via API from a mobile app on Cordova?

From Dev

Terraform GCP Data catalog Policy Tag

From Dev

How to connect to a GCP (Google Cloud Platform) Cloud SQL instance from an IPV6 address?

Related Related

  1. 1

    Propagating Error messages in Google Cloud Platform (GCP)

  2. 2

    Building Google Cloud Platform Data Catalog on unstructured data

  3. 3

    Google Cloud Platform - Datastore - Python ndb API

  4. 4

    GCP: Full backup of the database in the google cloud platform

  5. 5

    Google Cloud Platform (GCP) Ingress unhealthy backend

  6. 6

    GCP: Duplicate an existing project in Google Cloud Platform

  7. 7

    Google Play Security alert about Google Cloud Platform (GCP) API keys

  8. 8

    While creating API Gateway in google cloud platform throwing unreachable error

  9. 9

    Accessing GCP Memorystore from Google Cloud Platform Cloud Shell

  10. 10

    Google Cloud Platform (GCP) Cloud Shell "Boost" feature missing

  11. 11

    GCP AI Platform cannot read .SAV file stored in Google Cloud Storage (Python)

  12. 12

    Google Cloud Platform Data Display

  13. 13

    Google Cloud Platform SDK with Python

  14. 14

    Is there a way to change a google cloud platform project to other GCP account?

  15. 15

    Google Cloud Platform (GCP): How to give additional roles to service account?

  16. 16

    How to monitor Google Cloud Platform (GCP) costs on an hourly basis?

  17. 17

    Google cloud platform | 100% API error rate when using google translation API

  18. 18

    The Python script for updating rules in the Cloud Armor in Google Cloud Platform by REST API

  19. 19

    Using Google Cloud Platform for scheduled recurring API data pull that then loads the data to BigQuery

  20. 20

    Google cloud platform support plan from API

  21. 21

    GCP python API. Accessing getiampolicy for gcp cloud sql instance

  22. 22

    Google cloud AI platform error in executing job

  23. 23

    Using Error report of Google Cloud Platform with ExpressJS

  24. 24

    Docker image run error on Google Cloud Platform

  25. 25

    GCP Cloud Functions for python output data file

  26. 26

    Error installing fbprophet on Google Cloud Platform AI Platform

  27. 27

    How to fetch data from Google Cloud Platform via API from a mobile app on Cordova?

  28. 28

    Terraform GCP Data catalog Policy Tag

  29. 29

    How to connect to a GCP (Google Cloud Platform) Cloud SQL instance from an IPV6 address?

HotTag

Archive