boto3을 사용하여 'Function'이라고 부른 EC2 태그의 값을 인쇄하려고하는데 약 12 개의 객체를 통해 코드가 실행 된 후 라인 7에 TypeError: 'NoneType' object is not iterable
오류가 발생합니다. . 해당 값이 None
인지 확인하여이 오류를 계속 잡으려고 시도했지만이 오류가 계속 발생합니다.boto3 TypeError : 'NoneType'객체가 반복 가능하지 않습니다.
import boto3
s = boto3.Session(profile_name='default')
ec2 = s.resource('ec2')
for i in ec2.instances.all():
for tag in i.tags:
if tag['Value'] is None:
print("No Value")
else:
if tag['Key'] == 'Function':
print(tag['Value'])
어떤 줄에서 예외가 발생합니까? i.tags가 None 일 수 있습니까? – jarmod
라인 7이므로 이해가됩니다. if i.tags가 None이면 : print ("No Value") '나는 또한 7 호선에서 같은 문제를받습니다. – tweeks200