代码执行在尝试使用发现方法从GCP云中检索磁盘详细信息时悬挂?
from google.oauth2 import service_account
from googleapiclient import discovery
def main():
cred = service_account.Credentials.from_service_account_file("json file path")
service = discovery.build("compute", "v1", credentials=cred)
request = service.disks().list(project="projectid", zone="us-central1-a")
print(request)
while request is not None:
response = request.execute()
print(response)
for disk in response["items"]:
# TODO: Change code below to process each `disk` resource:
print(disk)
request = service.disks().list_next(
previous_request=request, previous_response=response
)
if __name__ == "__main__":
main()
该代码能够成功打印(请求)数据,之后没有结果。我在项目中创建了磁盘。
from google.oauth2 import service_account
from googleapiclient import discovery
def main():
cred = service_account.Credentials.from_service_account_file("json file path")
service = discovery.build("compute", "v1", credentials=cred)
request = service.disks().list(project="projectid", zone="us-central1-a")
print(request)
while request is not None:
response = request.execute()
print(response)
for disk in response["items"]:
# TODO: Change code below to process each `disk` resource:
print(disk)
request = service.disks().list_next(
previous_request=request, previous_response=response
)
if __name__ == "__main__":
main()
The code is successfully able to print(request) data after which there is no result. I have as disk created in the project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码中有一个段循环,而无需终止子句。那就是被卡住的地方。您可以通过以下方式重写该部分:
You have a while loop in the code without the termination clause. Thats where its getting stuck. You could rewrite that part in the following way: