【问题标题】:"ValueError: Protocol message DeidentifyTemplate has no 'deidentifyTemplate' field."“ValueError:协议消息 DeidentifyTemplate 没有 'deidentifyTemplate' 字段。”
【发布时间】:2019-10-15 05:33:40
【问题描述】:

我正在尝试使用 GCP DLP API 客户端库(Python 3)创建 DE 识别模板。我已经使用 POST 方法成功创建了去标识化模板。 DE-identification 模板的作用是使用 Google KMS 封装的 Key 加密一些 PII 字段。

      client.create_deidentify_template(
          parent=parent,
          deidentify_template=deidentify_template,
          template_id=templateId,
          retry=google.api_core.gapic_v1.method.DEFAULT,
          timeout=google.api_co
          re.gapic_v1.method.DEFAULT,
          metadata=None)

错误:

ValueError:协议消息 DeidentifyTemplate 没有“deidentifyTemplate”字段。

【问题讨论】:

  • 异常ValueError:当内置操作或函数接收到具有正确类型但值不适当的参数时引发,并且该情况没有通过更精确的异常(例如IndexError)来描述。跨度>

标签: python-3.x google-cloud-platform google-cloud-dlp


【解决方案1】:

我相信你的参数deidentify_template=deidentify_template 是问题所在。 来自Google DLP API Python Client 文档:

deidentify_template (Union[dict, DeidentifyTemplate]) – 要创建的 DeidentifyTemplate。

如果提供了一个dict,它必须与protobuf消息DeidentifyTemplate的格式相同

对于DeidentiftTemplate is defined,您缺少一些参数:

显示名称 显示名称(最多 256 个字符)。

说明 简短说明(最多 256 个字符)。

创建时间 inspectTemplate 的创建时间戳,仅输出字段。

更新时间 inspectTemplate 的最后更新时间戳,仅输出字段。

deidentify_config //////////////模板的核心内容//////////////

创建时间 字段 google.privacy.dlp.v2.DeidentifyTemplate.create_time

deidentify_config 字段 google.privacy.dlp.v2.DeidentifyTemplate.deidentify_config

说明 字段 google.privacy.dlp.v2.DeidentifyTemplate.description

显示名称 字段 google.privacy.dlp.v2.DeidentifyTemplate.display_name

姓名 字段 google.privacy.dlp.v2.DeidentifyTemplate.name

更新时间 字段 google.privacy.dlp.v2.DeidentifyTemplate.update_time

【讨论】:

  • 这里的大部分参数都是可选的,API调用后的响应格式。
【解决方案2】:

deidentify_template:DLP api 采用字段名称而不是字段类型。 例如:

{
    "display_name" : "de_identification_template",
    "description" : "masking sensitive data",
    "deidentify_config" : {
             "info_type_transformations" : {
                      #your specification here.
                }

}

您必须为您的 python DLP api 调用将“deidentifyConfig”更改为“deidentify_config”。

https://cloud.google.com/dlp/docs/creating-templates-deid 非常具有误导性。它仅适用于 Web DLP API POST,不适用于 python 客户端库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多