【问题标题】:Getting broken link error whle Using App Engine service accounts使用 App Engine 服务帐户时出现链接断开错误
【发布时间】: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/_webapp2‌​5.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


【解决方案1】:

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

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

阅读更多关于处理程序的信息here

【讨论】:

  • 我刚刚更新了我的 app.yaml(也更新了有问题的 app.yaml),并尝试浏览链接bigquerymashup.appspot.com/listdatasets,但现在它给出了另一个错误 Traceback(最近一次调用最后一次):文件“/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py”,第 710 行,在 call handler.get(*groups) TypeError: get() 中正好 1 个参数(给定 2 个)
  • 将“/listdatasets(.*)”更改为“/listdatasets”。另请注意,您更新的 app.yaml 不正确 - 您不需要在 app.yaml 中包含“url: /listdatasets”行。包罗万象的 "url: .*" 处理程序无论如何都应该放在最后,因为它会在点击下面的 /listdatasets 处理程序之前匹配每个 URL。这超出了您原始问题的范围(并且在上面的链接中都有解释),但我会看看更新我们的示例。
  • thnks dat 工作正常。我还有一个疑问。为了让这件事正常工作,我必须将它上传到 apppot。是否可以使用 App Engine 服务帐户在 localhost 中运行它
  • 否,目前无法在本地使用 App Engine 服务帐号。
猜你喜欢
  • 1970-01-01
  • 2012-09-02
  • 2012-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
  • 2014-02-20
  • 2013-10-11
相关资源
最近更新 更多