簡體   English   中英

在計算引擎中租賃App Engine任務

[英]Leasing app engine task in compute engine

我正在嘗試從計算引擎實例中的拉入隊列中租用App Engine任務,但它一直顯示此錯誤:

{
 "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']

似乎是一個身份驗證問題,但是如果我使用廢話虛構的項目名稱執行相同的租用請求,則會給我完全相同的錯誤,因此我不確定。
我還啟動了啟用了任務隊列的實例。
任何幫助將不勝感激

萬一其他人陷入這樣的問題,我將解釋它現在如何工作。 首先,我使用了另一種(較短的)身份驗證方法:

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結尾的電子郵件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM