1

我正在尝试从计算引擎实例中的拉取队列中租用应用程序引擎任务,但它一直出现此错误:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "you are not allowed to make this api call"
   }
  ],
  "code": 403,
  "message": "you are not allowed to make this api call"
 }
}

这是我正在使用的代码:

import httplib2, json, urllib
from oauth2client.client import AccessTokenCredentials
from apiclient.discovery import build

def FetchToken():
    METADATA_SERVER = ('http://metadata/computeMetadata/v1/instance/service-accounts')
    SERVICE_ACCOUNT = 'default'

    http = httplib2.Http()

    token_uri = '%s/%s/token' % (METADATA_SERVER, SERVICE_ACCOUNT)
    resp, content = http.request(token_uri, method='GET',
                         body=None,
                         headers={'Metadata-Flavor': 'Google'})
    print token_uri
    print content
    if resp.status == 200:
        d = json.loads(content)
        access_token = d['access_token']  # Save the access token
        credentials = AccessTokenCredentials(d['access_token'],
                                        'my-user-agent/1.0')
        autho = credentials.authorize(http)
        print autho
        return autho
    else:
        print resp.status

task_api = build('taskqueue', 'v1beta2')

lease_req = task_api.tasks().lease(project='project-name',
                                    taskqueue='pull-queue',
                                    leaseSecs=30,
                                    numTasks=1)


result = lease_req.execute(http=FetchToken()) ####ERRORS HERE
item = result.items[0]
print item['payload']

这似乎是一个身份验证问题,但如果我使用胡说八道的项目名称执行相同的租赁请求,它会给我完全相同的错误,所以我无法确定。
我还启动了启用任务队列的实例。
任何帮助将不胜感激

4

1 回答 1

0

如果其他人遇到这样的问题,我将解释它现在是如何工作的。首先,我使用了一种不同的(更短的)身份验证方法:

from oauth2client import gce

credentials = gce.AppAssertionCredentials('')
http = httplib2.Http()
http=credentials.authorize(http)
credentials.refresh(http)
service = build('taskqueue', 'v1beta2', http=http)

其次,我的租约请求被拒绝的原因是在queue.yaml 中我的服务帐户电子邮件被设置为作者电子邮件。在文档中提到,以@gmail.com结尾的电子邮件在设置为作者电子邮件时将不具有用户电子邮件的权限。没有提到这延伸到以@developer.gserviceaccount.com结尾的电子邮件。

于 2014-10-15T09:56:28.470 回答