Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
迭代AWS json响应python_Python_Amazon Web Services - Fatal编程技术网

迭代AWS json响应python

迭代AWS json响应python,python,amazon-web-services,Python,Amazon Web Services,尝试通过AWS json输出进行迭代,并使用以下代码检查ECR中是否存在特定版本。但我总是得到“图像在ECR中不存在!”即使图像标签存在 client = boto3.client('ecr') response = client.list_images(registryId='my_account_number', repositoryName='my_app') for i in response['imageIds']: if i['imageTag'] != version:

尝试通过AWS json输出进行迭代,并使用以下代码检查ECR中是否存在特定版本。但我总是得到“图像在ECR中不存在!”即使图像标签存在

client = boto3.client('ecr')
response = client.list_images(registryId='my_account_number', repositoryName='my_app')

for i in response['imageIds']:
    if i['imageTag'] != version:
        print(response)
        print('Image does not exist in ECR!')
        quit()
    else:
        pass

将代码更改为运行,直到找到所需的版本:

client = boto3.client('ecr')
response = client.list_images(registryId='my_account_number', repositoryName='my_app')

for i in response['imageIds']:
    if i['imageTag'] == version:
        print('Found matching version!')
        print(i)
        break
else:
    print('Image does not exist in ECR!')

如果找不到正确的版本,
“ECR中不存在图像!”将被打印。

如果['imageTag']!=版本:
我想你的意思是
I['imageTag']
?是的。。调整了上述内容。。同样的结果,然后调试它。添加
打印(i['imageTag'])
。我们无法为您调试它,因为我们没有您得到的响应。好的,它只返回第一个图像标记,而不返回其他图像标记。因此,我似乎丢失了一些代码,所以它会遍历所有图像标记。这是因为,一旦找到第一个不匹配的图像(在本例中是第一个),您就退出了。相反,您需要继续,直到找到匹配的版本,然后退出。