Search code examples
python-3.xgoogle-cloud-platformgoogle-cloud-dlp

"ValueError: Protocol message DeidentifyTemplate has no 'deidentifyTemplate' field."


I am trying to create DE-identification template using GCP DLP API client library(Python 3). I have successfully created de-identification template using POST method. What the DE-identification template dose is encrypt some PII fields using Google KMS wrapped Key.

      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)

Error:

ValueError: Protocol message DeidentifyTemplate has no 'deidentifyTemplate' field.


Solution

  • deidentify_template: DLP api take field name not field type. for example :

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

    you must change "deidentifyConfig" to "deidentify_config" for you python DLP api call.

    https://cloud.google.com/dlp/docs/creating-templates-deid is quite misleading. it's only for web DLP API POST, not for python client library.