指定磁盘类型时,无法使用python代码创建磁盘
我正在使用python3创建磁盘。在尝试创建磁盘时,我使用下面的body配置。如果我不使用“类型”:“pd标准”或“类型”:“pd ssd”,我可以创建磁盘: 但当使用“类型”:“pd标准”或“类型”:“pd ssd”时,我得到以下错误:指定磁盘类型时,无法使用python代码创建磁盘,python,python-3.x,google-cloud-platform,Python,Python 3.x,Google Cloud Platform,我正在使用python3创建磁盘。在尝试创建磁盘时,我使用下面的body配置。如果我不使用“类型”:“pd标准”或“类型”:“pd ssd”,我可以创建磁盘: 但当使用“类型”:“pd标准”或“类型”:“pd ssd”时,我得到以下错误: Traceback (most recent call last): File "C:/Users/myuser/PycharmProjects/pythonProject/cretedisk.py", line 31, in <
Traceback (most recent call last):
File "C:/Users/myuser/PycharmProjects/pythonProject/cretedisk.py", line 31, in <module>
print(create_disk(compute, project, zone))
File "C:/Users/myuser/PycharmProjects/pythonProject/cretedisk.py", line 24, in create_disk
return compute.disks().insert(
File "C:\Users\myuser\PycharmProjects\pythonProject\venv\lib\site-packages\googleapiclient\_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\myuser\PycharmProjects\pythonProject\venv\lib\site-packages\googleapiclient\http.py", line 907, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://compute.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/disks?alt=json returned "Invalid value for field 'resource.type': 'pd-standard'. The URL is malformed.">
我不确定它为什么尝试错误的url:
https://compute.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/disks
在我看来,图书馆里好像有个bug。有没有人尝试过并面对过这样的问题,或者有解决这个错误的方法
感谢您的光临,类型字段显示:
描述用于创建磁盘的磁盘类型的磁盘类型资源的URL。在创建磁盘时提供此选项。例如:projects//zones//diskTypes/pd-standard
我想您需要的是类型
的完整URL,而不仅仅是pd标准
,因此:
https://www.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/diskTypes/pd-standard
你能在你的createDisk.py
文件中包含你的create\u disk
功能吗?@Dustin:很抱歉,我无法理解你的上述陈述。谢谢你花了宝贵的时间。你是对的。甚至我也在看同一个页面,但不知何故错过了上面粘贴的url语句。可能是因为在调用compute.disks().insert时,我已经在project和zone参数中传递了这些详细信息,所以我不希望重复项目名称和区域。我认为谷歌应该纠正这一点,因为当您必须重复相同的in-type参数时,传递project和zone没有任何意义。
https://compute.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/disks
https://www.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/diskTypes/pd-standard