Google DLP:'Resource' 对象没有属性 'content'
Google DLP: 'Resource' object has no attribute 'content'
我有一个一直在测试 Google 的 DLP 的脚本突然停止工作:
def redact_text(text_list):
service = build_client()
content = service.content()
items = []
for text in text_list:
items.append({
"type": "text/plain",
"value": text
})
data = { "items":items,
"inspectConfig": {
"minLikelihood": "LIKELIHOOD_UNSPECIFIED",
"maxFindings": 0,
"includeQuote": False
},
"replaceConfigs": [{'replaceWith': redacts[info], 'infoType':{'name': info}} for info in redacts.keys()]
}
request = content.redact(body=data)
response = request.execute()
return response
def build_client():
scopes = ['https://www.googleapis.com/auth/cloud-platform']
credentials = ServiceAccountCredentials.from_json_keyfile_name('cred_name.json', scopes=scopes)
http_auth = credentials.authorize(Http())
service = build('dlp', 'v2beta1', http=http_auth)
return service
if __name__ == '__main__':
test_list = []
test_text = "My name is Jenny and my number is (555) 867-5309, you can also email me at notarealemail@fakegmail.com another email you can reach me at is email@email.com. "
task = "inspect"
test_list.append(test_text)
test_list.append("bill (555) 202-4578, that one place down the road some_email@notyahoo.com")
print(test_list)
result = redact_text(test_list)
print(result)
通常我会得到回复,但今天我一直在回复:
Traceback (most recent call last):
File "test_dlp.py", line 82, in <module>
response = redact_text(text_list)
File "test_dlp.py", line 42, in redact_text
content = service.content()
AttributeError: 'Resource' object has no attribute 'content'
我没有对此脚本进行任何更改,并且它之前一直有效。
5 月 1 日,测试版 api 已弃用,因为 GA 版本现在可用。
在大多数情况下,您的脚本可以正常工作,但切换到版本 'v2'。
脚本的第二部分需要更改的是 ContentItem "aka items" 现在只是一个项目,而不是列表。
您可以使用
发送单个请求
item = {'value': content_string}
或者,如果您仍希望将此批处理为单个请求,则可以使用 table。 (我没有 运行 这个所以请原谅编译错别字,但是 api 表面是这样的。)
var rows = []
var headers = [{"name": "column1"}]
for text in text_list:
rows.append({
"string_value": text,
})
item = {
"table": {
"headers": headers,
"rows": rows
}
}
data = { "item":item,
"inspectConfig": {
"minLikelihood": "LIKELIHOOD_UNSPECIFIED",
"maxFindings": 0,
"includeQuote": False
},
"replaceConfigs": [{'replaceWith': redacts[info], 'infoType':{'name': info}} for info in redacts.keys()]
}
我有一个一直在测试 Google 的 DLP 的脚本突然停止工作:
def redact_text(text_list):
service = build_client()
content = service.content()
items = []
for text in text_list:
items.append({
"type": "text/plain",
"value": text
})
data = { "items":items,
"inspectConfig": {
"minLikelihood": "LIKELIHOOD_UNSPECIFIED",
"maxFindings": 0,
"includeQuote": False
},
"replaceConfigs": [{'replaceWith': redacts[info], 'infoType':{'name': info}} for info in redacts.keys()]
}
request = content.redact(body=data)
response = request.execute()
return response
def build_client():
scopes = ['https://www.googleapis.com/auth/cloud-platform']
credentials = ServiceAccountCredentials.from_json_keyfile_name('cred_name.json', scopes=scopes)
http_auth = credentials.authorize(Http())
service = build('dlp', 'v2beta1', http=http_auth)
return service
if __name__ == '__main__':
test_list = []
test_text = "My name is Jenny and my number is (555) 867-5309, you can also email me at notarealemail@fakegmail.com another email you can reach me at is email@email.com. "
task = "inspect"
test_list.append(test_text)
test_list.append("bill (555) 202-4578, that one place down the road some_email@notyahoo.com")
print(test_list)
result = redact_text(test_list)
print(result)
通常我会得到回复,但今天我一直在回复:
Traceback (most recent call last):
File "test_dlp.py", line 82, in <module>
response = redact_text(text_list)
File "test_dlp.py", line 42, in redact_text
content = service.content()
AttributeError: 'Resource' object has no attribute 'content'
我没有对此脚本进行任何更改,并且它之前一直有效。
5 月 1 日,测试版 api 已弃用,因为 GA 版本现在可用。
在大多数情况下,您的脚本可以正常工作,但切换到版本 'v2'。
脚本的第二部分需要更改的是 ContentItem "aka items" 现在只是一个项目,而不是列表。
您可以使用
发送单个请求item = {'value': content_string}
或者,如果您仍希望将此批处理为单个请求,则可以使用 table。 (我没有 运行 这个所以请原谅编译错别字,但是 api 表面是这样的。)
var rows = []
var headers = [{"name": "column1"}]
for text in text_list:
rows.append({
"string_value": text,
})
item = {
"table": {
"headers": headers,
"rows": rows
}
}
data = { "item":item,
"inspectConfig": {
"minLikelihood": "LIKELIHOOD_UNSPECIFIED",
"maxFindings": 0,
"includeQuote": False
},
"replaceConfigs": [{'replaceWith': redacts[info], 'infoType':{'name': info}} for info in redacts.keys()]
}