2

我有一种方法,可以为 Google 的 DLP检查 API构建多个项目的表,该 API 可以采用ContentItem

以下是请求的构造方式:

def redact_text(text_list):
    dlp = google.cloud.dlp.DlpServiceClient()
    project = 'my-project'
    parent = dlp.project_path(project)
    items = build_item_table(text_list)

    info_types = [{'name': 'EMAIL_ADDRESS'}, {'name': 'PHONE_NUMBER'}]
    inspect_config = {
        'min_likelihood': "LIKELIHOOD_UNSPECIFIED",
        'include_quote': True,
        'info_types': info_types
    }
    response = dlp.inspect_content(parent, inspect_config, items)

    return response


def build_item_table(text_list):
    rows = []
    for item in text_list:
        row = {"values": [{"stringValue": item}]}
        rows.append(row)
    table = {"table": {"headers": [{"name": "something"}], "rows": rows}}
    return table

当我运行它时,我得到了错误,ValueError: Protocol message Value has no "stringValue" field.即使这个例子文档另有说明。

我如何构建请求有什么问题吗?

编辑:这是来自的输出build_item_table

{
    'table':
    {
        'headers': 
        [
            {'name': 'value'}
        ], 
        'rows': 
        [
            {
                'values': 
                [
                    {
                        'stringValue': 'My name is Jenny and my number is (555) 867-5309, you can also email me at anemail@gmail.com, another email you can reach me at is email@email.com.  '
                    }
                ]
            }, 
            {
                'values': 
                [
                    {
                        'stringValue': 'Jimbob Doe (555) 111-1233, that one place down the road some_email@yahoo.com'
                    }
                ]
            }
        ]
    }
}
4

1 回答 1

3

尝试 string_value .... python 使用字段名称,而不是类型名称。

于 2018-05-10T22:21:15.157 回答