【问题标题】:NotAllowedError on front main page '/'前面主页上的 NotAllowedError '/'
【发布时间】:2013-11-09 16:18:00
【问题描述】:

我尝试将用户的主页'/' 设置为登录或不登录,但我得到了NotAllowedError。这适用于本地服务器。但是,它似乎在真正的公共服务器中不起作用。

NotAllowedError 是否意味着遵守 Google App Engine 标准,即不在首页或其他地方登录?

这是错误:

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~map-jobs/2.371277816538602179/main.py", line 294, in get
    user_url = users.create_login_url() # raise NotAllowedError
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/users.py", line 256, in create_login_url
    raise NotAllowedError
NotAllowedError

这是我的MainHandler

class MainHandler(BaseHandler):
  def get(self):
    user = users.get_current_user()
    logout_url = users.create_logout_url(self.request.uri)
    profile=''
    if user:
      profile = Profile.query(Profile.user_id==user.user_id())
      if profile.count() <= 0:
        profile = Profile()
        profile.user_id = user.user_id()
        profile.email = user.email()
        profile.firstname = user.nickname()
        profile_key = profile.put()
      else:
        profile_key = Profile.query(Profile.user_id==user.user_id())
      profile = profile_key.get()
      current_user = 'Hello, '+ user.nickname()
      user_url = logout_url
      title = "Click to logout from Google."
    else:
      current_user = 'Google Sign in'
      user_url = users.create_login_url(self.request.uri) # raise NotAllowedError
      title = "Click to sign in with your Google Account."
    values = {
      'current_user' : current_user,
      'user_url' : user_url,
      'profile' : profile,
    }
    self.render_html('index.html',values)

这是我webapp2.WSGIApplication的一部分:

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

这是我的 app.yaml:

application: map-jobs
version: 2
runtime: python27
api_version: 1
threadsafe: yes

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

- url: /(.*\.(gif|png|jpg|js|css|woff|ttf|svg))
  static_files: static/\1
  upload: static/(.*\.(gif|png|jpg|js|css|woff|ttf|svg))

- url: /templates/.*
  script: templates.app

- url: .*
  script: main.app


libraries:
- name: webapp2
  version: "2.5.2"

- name: jinja2
  version: "2.6"

【问题讨论】:

  • 您尚未显示您的 app.yaml 以及您启用了何种身份验证(例如 google 应用程序、openid 等)。我对有限信息的猜测,类似以下的事情正在发生,你有一个应用域登录的身份验证,但用户已经登录到谷歌,但不是谷歌应用域,所以无法创建登录 url。您应该详细说明您的设置。
  • 我已经添加了我的 app.yaml。

标签: function google-app-engine exception-handling


【解决方案1】:

没关系,我只是犯了一个错误。我应该在我的应用程序设置中使用 Google Accounts API 而不是 Google Apps Domain

【讨论】:

  • 是的,我认为它会是这样的。
  • 此对话中的设置是关于应用程序登录(GAE 登录)和 OAuth 登录,可以使用 API 密钥在 Google API 控制台中找到。很难复制和解释,但这涉及使用两个身份验证。只能使用一个登录名。一旦确定要使用哪一个,用户就可以使用来自 API 的信息。
猜你喜欢
  • 2016-08-13
  • 2012-09-04
  • 1970-01-01
  • 2017-02-01
  • 2018-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-10
相关资源
最近更新 更多