尝试使用 GAE python 在 Bigquery 上运行查询时出现以下错误。
HttpError 403 when requesting https://www.googleapis.com/bigquery/v2/projects/publicdata/queries?alt=json returned "Access Denied: Job publicdata:job_c08d8f254c0449c2b3e26202e62ca5fa: RUN_QUERY_JOB">
这是 main.py 代码
import httplib2
import os
from apiclient.discovery import build
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import AppAssertionCredentials
# BigQuery API Settings
SCOPE = 'https://www.googleapis.com/auth/bigquery'
PROJECT_NUMBER = 'publicdata' # REPLACE WITH YOUR Project ID
# Create a new API service for interacting with BigQuery
credentials = AppAssertionCredentials(scope=SCOPE)
httpss = credentials.authorize(httplib2.Http())
bigquery_service = build('bigquery', 'v2', http=httpss)
class GetTableData(webapp.RequestHandler):
def get(self):
queryData = {'query':'SELECT word,count(word) AS count FROM publicdata:samples.shakespeare GROUP BY word;',
'timeoutMs':10000}
queryData = bigquery_service.jobs()
queryReply = queryData.query(projectId=PROJECT_NUMBER,body=queryData).execute()
self.response.out.write(queryReply)
application = webapp.WSGIApplication(
[('/queryTableData',GetTableData)
],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
这是 App.yaml
application: bigquerymashup
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /css
static_dir: css
- url: /js
static_dir: js
- url: /img
static_dir: img
- url: .*
script: main.py
我正在使用 App Engine 服务帐户进行身份验证