Google cloud DLP API Image redaction in Python错误信息类型

2024-06-26 08:45:20 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,我正在尝试google的示例代码,用于从python中的图像编辑信息,我成功地检查了字符串中的info_类型,但是当我尝试使用Anaconda发行版中的图像检查示例代码时,它给了我以下错误:

    ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-44-d8dba8a7c706> in <module>()
----> 1 redact_image('python-pdf-redaction', 'redaction.jpg', 'redaction_out.jpg',info_types, min_likelihood='LIKELY', mime_type=None)

<ipython-input-41-fc41518240a7> in redact_image(project, filename, output_filename, info_types, min_likelihood, mime_type)
     71         parent, inspect_config=inspect_config,
     72         image_redaction_configs=image_redaction_configs,
---> 73         byte_item=byte_item)
     74 
     75     # Write out the results.

~/anaconda3/lib/python3.6/site-packages/google/cloud/dlp_v2/gapic/dlp_service_client.py in redact_image(self, parent, inspect_config, image_redaction_configs, include_findings, byte_item, retry, timeout, metadata)
    431             image_redaction_configs=image_redaction_configs,
    432             include_findings=include_findings,
--> 433             byte_item=byte_item,
    434         )
    435         return self._inner_api_calls["redact_image"](

TypeError: {'name': 'FIRST_NAME'} has type dict, but expected one of: bytes, unicode

我的代码是:

^{pr2}$

我不确定是否需要更改数据类型或它的其他内容,我找不到任何与此问题相关的引用。 你的反应将是高度赞赏。在

编辑: 我已经解决了我的错误,我必须列出一个信息类型列表来指定我要编辑的信息类型。 i、 e.info_types=['名字','姓氏','电子邮件地址']


Tags: 代码inimageinfo信息config类型type
1条回答
网友
1楼 · 发布于 2024-06-26 08:45:20

代码示例需要改进的一点是:

byte_item={'type':内容类型索引,'data':f.read()}

可以更改为

byte_item={'type':'IMAGE','data':f.read()}

然后,您可以去掉mimetypefoo,假设您知道您只发送受支持的图像类型。在

相关问题 更多 >