Ich habe eine Antwort Syntax vom Typ dict
:Wie kann auf den Diktatwert zugegriffen werden?
{
'StoppingInstances': [
{
'InstanceId': 'string',
'CurrentState': {
'Code': 123,
'Name': 'pending'|'running'|'shutting-down'|'terminated'|'stopping'|'stopped'
},
'PreviousState': {
'Code': 123,
'Name': 'pending'|'running'|'shutting-down'|'terminated'|'stopping'|'stopped'
}
},
]
}
Wenn ich nun, wenn der current ist stopping
, wie dies zu tun, überprüfen muß?
print "Stopping instance Now",response['StoppingInstances']
for instance in response['StoppingInstances']:
if instance['CurrentState']['Name'] == "stopping":
print "Still Stooping"
if instance['CurrentState']['Name'] == "stopped":
print "Instance Stopped"
print "Now Starting the instance"
response_new = client.start_instances(InstanceIds=[instance_id])
for start_instance in response_new['StartingInstances']:
if start_instance['CurrentState']['Name'] == "running":
print "Instance is UP and running"
else:
print "Some Error occured!!"
einfach auf Ihre Daten suchen. 'response ['StoppingInstances']' ist eine Liste (Array in JSON), die Sie mit einer Ganzzahl indizieren müssen. – jonrsharpe