【发布时间】:2018-09-28 21:30:59
【问题描述】:
现有文档
https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert
声明调用的返回类型将是一个包含多个状态值的字典。另外,就连他们的python examples也显示返回类型是dict类型。
实际发生的情况
我所经历的是,这个电话实际上给了我None:
config = {
'name': "test-machine",
'machineType': "zones/us-central1-c/machineTypes/foobar",
'disks': [
{
'boot': True,
'autoDelete': True,
'deviceName': "test-machine",
...
}
}
operation = compute.instances().insert(project=PROJECT_NAME, zone=ZONE, body=config).execute()
wait_for_operation(compute, PROJECT_NAME, ZONE, operation["name"])
wait_for_operation() 函数直接取自 python 示例:
def wait_for_operation(compute, project, zone, operation):
print('Waiting for operation to finish...')
while True:
result = compute.zoneOperations().get(
project=project,
zone=zone,
operation=operation).execute()
if result['status'] == 'DONE':
print("done.")
if 'error' in result:
raise Exception(result['error'])
return result
time.sleep(1)
然而,我得到了这个错误:
Traceback (most recent call last):
File "gcloud_playground.py", line 113, in <module>
wait_for_operation(compute, PROJECT_NAME, ZONE, operation["name"])
TypeError: 'NoneType' object has no attribute '__getitem__'
实际发生的是我的实例已成功创建,但我不知道它是否已成功创建。
【问题讨论】:
标签: python google-compute-engine google-api-python-client google-apis-explorer