1

我正在关注本教程

https://developers.google.com/bigquery/docs/authorization#service-accounts-appengine

这是我的 main.py 代码

import httplib2

from apiclient.discovery import build
from google.appengine.ext import webapp
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 = 'XXXXXXXXXX' # REPLACE WITH YOUR Project ID

# Create a new API service for interacting with BigQuery
credentials = AppAssertionCredentials(scope=SCOPE)
http = credentials.authorize(httplib2.Http())
bigquery_service = build('bigquery', 'v2', http=http)


class ListDatasets(webapp.RequestHandler):
  def get(self):
    datasets = bigquery_service.datasets()
    listReply = datasets.list(projectId=PROJECT_NUMBER).execute()
    self.response.out.write('Dataset list:')
    self.response.out.write(listReply)


application = webapp.WSGIApplication(
                                     [('/listdatasets(.*)', ListDatasets)],
                                     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: .*
  script: main.py

是的,我已经在 google api 控制台 Team 选项卡中添加了应用引擎服务帐户名称,并且可以编辑权限。当上传应用程序并尝试访问它说的链接

Oops! This link appears to be broken.

之前我在本地运行它并尝试使用链接访问它localhost:8080。然后我认为可能在本地运行可能会给出错误,所以我将我的代码上传到

http://bigquerymashup.appspot.com/

但它仍然是错误的。

编辑: 更新 App.yaml

application: bigquerymashup
version: 1
runtime: python
api_version: 1

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.py

- url: /listdatasets
  script: main.py

但得到另一个错误

Traceback (most recent call last): File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp2‌​5.py", line 710, in call handler.get(*groups) TypeError: get() takes exactly 1 argument (2 given) 
4

1 回答 1

1

您需要定义一个与您要查找的 URL 匹配的脚本处理程序。

尝试:http://[your_app_id_here].appspot.com/listdatasets

在此处阅读有关处理程序的更多信息。

于 2012-11-12T10:58:38.470 回答