【问题标题】:Google AppEngine with Service Account but invalid Credentials具有服务帐户但凭据无效的 Google AppEngine
【发布时间】:2014-11-21 16:50:54
【问题描述】:

我尝试使用 Google App Engine 1.7.5 和 python 2.5 按照一个简单的示例 here 来使用组设置 API 获取组设置。 这是我的 app.yaml:

application: {{APP_ID}}
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: main.py

我的 main.py 如下:

def main():
    application = webapp.WSGIApplication([('/', TestHandler)])
    run_wsgi_app(application)

class TestHandler(webapp.RequestHandler):
    """Handles a request for the query page."""
    def get(self):
        self.response.out.write(Test())

def Test():
    credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/apps.groups.settings')
    http = credentials.authorize(httplib2.Http(memcache))
    service = build('groupssettings', 'v1', http=http)
    group = service.groups().get(groupUniqueId='{{GROUP_ID}}').execute()
    logging.error(group)

if __name__=="__main__":
    main()

这是告诉我无效凭据的堆栈跟踪!

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 714, in __call__
    handler.get(*groups)
  File "D:\Projets\GS\main.py", line 26, in get
    self.response.out.write(Test())
  File "D:\Projets\GS\main.py", line 41, in Test
    group = service.groups().get(groupUniqueId='{{GROUP_ID}}').execute()
  File "D:\Projets\GS\oauth2client\util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "D:\Projets\GS\apiclient\http.py", line 723, in execute
    raise HttpError(resp, content, uri=self.uri)
HttpError: <HttpError 401 when requesting https://www.googleapis.com/groups/v1/groups/{{GROUP_ID}}?alt=json returned "Invalid Credentials">
INFO     2014-11-21 15:51:45,423 dev_appserver.py:3104] "GET / HTTP/1.1" 500 -
INFO     2014-11-21 15:51:45,611 dev_appserver.py:3104] "GET /favicon.ico HTTP/1.1" 404 -

之前有没有人遇到过这个错误或者知道根本原因?

【问题讨论】:

    标签: python google-app-engine service-accounts google-groups-settings


    【解决方案1】:

    您是否为项目启用了通过开发者控制台访问群组 API 的权限?这是一个简单的步骤,但试图让 API 运行的人们经常会错过。

    另外,我建议使用 OAuth as described here 的装饰器模式来简化授权流程的推理。

    此外,您的 app.yaml 应指定 python27 而不仅仅是 python。 App Engine 运行 python27

    【讨论】:

    • 我已经在控制台中添加并授权了GroupSettings API,但是如何在里面进行授权CPanel呢?我试图授权 {{APP_ID}}@appspot.gserviceaccount.com 到相同的范围,但没有得到它说 URL 应该包含主机。
    • 是的 - 我们也遇到了这个问题 - 打开 GroupSettings API 没有任何区别。
    • 为了清楚起见,{{GROUP_ID}} 在您的问题中指的是您尝试获取的群组的电子邮件地址,但您将其设为匿名?
    猜你喜欢
    • 1970-01-01
    • 2014-09-24
    • 2015-10-28
    • 2016-03-03
    • 1970-01-01
    • 2015-04-29
    • 2021-11-17
    • 2016-11-18
    • 1970-01-01
    相关资源
    最近更新 更多