【发布时间】:2012-10-31 14:02:30
【问题描述】:
我正在学习本教程
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 控制台“团队”选项卡中添加了应用引擎服务帐户名称,并且可以编辑权限。 当上传应用程序并尝试访问它说的链接时
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/_webapp25.py", line 710, in call handler.get(*groups) TypeError: get() takes exactly 1 argument (2 given)
【问题讨论】:
-
1.您是否在此行添加了您的项目编号? PROJECT_NUMBER = 'XXXXXXXXXX' # 替换为您的项目 ID 2. 您要访问哪个链接?你的 app.yaml 文件是什么样的?
-
是的,我确实添加了项目编号。我已使用 app.yaml 和其余详细信息更新了问题。我尝试使用 localhost:8080 和 bigquerymashup.appspot.com 访问我上传代码的位置
标签: python google-app-engine oauth-2.0 google-bigquery google-api-python-client