根据AWS boto3 Inspector2 Docs,我使用boto3 Python在循环中使用list_findings((方法列出Inspectorv2的结果。对于列表操作的第一个请求,我必须将此参数的值设置为null,但在所有这些情况下,变量next_token:都会出错
-
nextToken=无:botocore.exceptions.ParamValidationError:参数验证失败:参数nextToken的类型无效,值:None,类型:<类"NoneType">,有效类型:<类"str">
-
nextToken='null':botocore.errorfactory.ValidationException:调用ListFindings操作时发生错误(ValidationException(:操作"ListFindings"中的分页令牌异常:无效的有效负载包装架构-24855
-
nextToken=空字符串:调用ListFindings操作时发生错误(ValidationException(:操作"ListFindings"中的分页令牌异常:无效负载(无加密架构版本(
这是我的代码:
import boto3
inspector = boto3.client("inspector2")
next_token = "" # I change the value of this variable
while True:
response = inspector.list_findings(
filterCriteria={
'findingStatus': [
{
'comparison': 'EQUALS',
'value': 'ACTIVE'
},
],
'findingType': [
{
'comparison': 'EQUALS',
'value': 'PACKAGE_VULNERABILITY'
},
],
},
nextToken=next_token
)
next_token= response.get("nextToken")
# Some Code Here
if next_token == None:
break
我对第一个请求的nextToken的值应该是多少感到困惑?
按照AWS文档中的解释,使用分页会更容易:
# Create a client
inspector = boto3.client("inspector2")
# Create a reusable Paginator
paginator = inspector.get_paginator('list_findings')
# Create a PageIterator from the Paginator
page_iterator = paginator.paginate(filterCriteria={
'findingStatus': [
{
'comparison': 'EQUALS',
'value': 'ACTIVE'
},
],
'findingType': [
{
'comparison': 'EQUALS',
'value': 'PACKAGE_VULNERABILITY'
},
],
})
for page in page_iterator:
print(page)