【问题标题】:GCE - basic API usage - InstancesGCE - 基本 API 使用 - 实例
【发布时间】:2015-09-06 15:33:16
【问题描述】:

我想在 Python API 中使用“实例”...由于某种原因,我的代码返回空错误:

Error: []

我的代码:

email = "somecode@developer.gserviceaccount.com"
with open("somefile.p12") as f:
   pkey = f.read()
cred = SignedJwtAssertionCredentials(email,key, "https://www.googleapis.com/auth/devstorage.read_write")
compute = build('compute','v1',credentials=cred)

然后用最简单的 API 调用:

compute.instances().list(project="firebase-client", zone="us-central1-f").execute()

错误弹出...

【问题讨论】:

  • 您使用 pkey = ...,但随后将其用作 SignedJwtAssertionCredentials(email, key, ...) — 是拼写问题吗?
  • 另外,这是我在 Python 中实现 GCE 身份验证的方法:github.com/mbrukman/cloud-launcher/blob/master/src/… — 请注意,我在此处请求计算范围 https://www.googleapis.com/auth/compute
  • 是的,范围 url 确实是问题所在。 (pkey 在我的代码上没问题:))谢谢 :]

标签: google-compute-engine


【解决方案1】:

正如评论中提到并确认的那样,这里的解决方案是使用正确的范围:https://www.googleapis.com/auth/compute 是您想要对 Google Compute Engine API 进行读写访问的对象。

问题代码示例中的范围 URL:https://www.googleapis.com/auth/devstorage.read_write 改为提供对 Google Cloud Storage API 的读写访问权限。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2014-09-14
    相关资源
    最近更新 更多