I'm getting a server list from aws
and print them, however sometimes I get some missing keys:
>>> servers=ec2_client.describe_instances()
>>> for r in servers['Reservations']:
... for i in r['Instances']:
... print(i['InstanceId'], i['PrivateIpAddress'], i['PublicIpAddress'])
...
i-x x.y.z.p x.y.z.w
i-y x.y.z.p x.y.z.w
i-t x.y.z.p x.y.z.w
i-r x.y.z.p x.y.z.w
i-e x.y.z.p x.y.z.w
i-s x.y.z.p x.y.z.w
i-e x.y.z.p x.y.z.w
i-r x.y.z.p x.y.z.w
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
KeyError: 'PublicIpAddress'
How do I print it while ignoring missing keys (in a nice way)?