【问题标题】:gcp datacatalog_v1beta1 create taxonomy and policy tags failedgcp datacatalog_v1beta1 创建分类和策略标签失败
【发布时间】:2020-05-20 15:15:38
【问题描述】:

我正在尝试使用 Python Client for Google Cloud Data Catalog API beta 1 来创建分类和策略标签。这是我的代码:

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)

get_taxonomy() 出现以下错误

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

对于 create_taxonomy() 我得到了:

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

有什么想法吗? 感谢您的帮助!

顺便说一句,google api 调用确实有效,它通过以下示例返回 200。

所以我将代码更改为:

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

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

还是一样的501错误

【问题讨论】:

    标签: google-cloud-platform google-api-python-client google-data-api


    【解决方案1】:

    @hdu,我在客户端库存储库中提交了一个描述 501 错误的错误:https://github.com/googleapis/python-datacatalog/issues/33。 [已编辑] 此错误已修复。

    尽管出现501 错误,但我相信您的脚本中还有另一个小问题:

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

    GET Taxonomy 需要请求的分类的资源名称作为参数,格式为projects/{project_id}/locations/{location_id}/taxonomies/{taxonomies_id} (source)。

    【讨论】:

      【解决方案2】:

      从文档click here 中,注意到错误消息 NOT_IMPLEMENTED (501) 已在此处描述。我想您需要在 client.get_taxonomy() 上使用参数,例如 project_id、region 和 cluster,因为资源具有这些参数。您可以查看文章click here 了解授权范围,也可以查看click here 了解 API 方法。

      【讨论】:

        猜你喜欢
        • 2023-01-30
        • 2020-12-29
        • 1970-01-01
        • 2019-08-18
        • 2021-01-16
        • 2015-04-30
        • 1970-01-01
        • 2020-01-26
        • 2019-09-03
        相关资源
        最近更新 更多