2016-08-02 84 views
0

我构建了一个简单的python应用程序,以便在Google App Engine上运行。代码:Google App Engine - 验证已部署版本的应用程序的问题

import webapp2 

from oauth2client.contrib.appengine import AppAssertionCredentials 
from apiclient.discovery import build 
from googleapiclient import discovery 
from oauth2client.client import GoogleCredentials 


class MainPage(webapp2.RequestHandler): 
def get(self): 
    self.response.headers['Content-Type'] = 'text/plain' 
    self.response.write('BigQuery App') 
    credentials = AppAssertionCredentials(
              'https://www.googleapis.com/auth/sqlservice.admin') 
    service = discovery.build('bigquery', 'v2', credentials=credentials) 

    projectId = '<Project-ID>' 

    query_request_body = { 
     "query": "SELECT a from Data.test LIMIT 10" 
    } 

    request = service.jobs().query(projectId=projectId, body=query_request_body) 
    response = request.execute() 

    self.response.write(response) 



app = webapp2.WSGIApplication([ 
('/', MainPage), 
], debug=True) 

我能够在本地(http://localhost:8080)部署此代码,一切正常,但是我得到以下错误500服务器错误,当我尝试将它部署到GAE使用:

appcfg.py -A <Project-Id> -V v1 update . 

这是我从错误报告控制台出现错误:

error: An error occured while connecting to the server: DNS lookup failed for URL:http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/https://www.googleapis.com/auth/sqlservice.admin/?recursive=True 

我相信这是一个auth问题,以确保我的服务帐户授权我通过gclo去ud认证服务帐户,我还从SDK中设置了设置的环境变量。

我一直试图解决这一段时间,任何指针都非常赞赏。谢谢。

此外,我一直在使用服务帐户身份验证,通过以下文档:​​它说我不应该能够在本地运行AppAsseritionCredenitals,这增加了我的困惑,因为我实际上可以没有错误。

编辑:

重新上传和重新授权我的服务帐户,我能够连接到服务器后。然而,授权错误与此继续:

HttpError: <HttpError 403 when requesting https://www.googleapis.com/bigquery/v2/projects/sqlserver-1384/queries?alt=json returned "Insufficient Permission"> 

回答

0

要解决“的错误,同时连接到服务器”,按照这个答案列出的说明:https://stackoverflow.com/questions/31651973/default-credentials-in-google-app-engine-invalid-credentials-error#= ,然后重新上传应用程序

然后,要求...返回“权限不足”时修复HttpError 403,则必须更改您请求的范围。以我为例,我请求:

credentials = AppAssertionCredentials(
          'https://www.googleapis.com/auth/sqlservice.admin') 

然而,谷歌的BigQuery正确的范围是:https://www.googleapis.com/auth/bigquery。它看起来像这样:

credentials = AppAssertionCredentials(
          'https://www.googleapis.com/auth/bigquery') 

如果您使用的是不同的API,无论使用何种范围在单证概述。

相关问题