Python 为什么我从AppEngine获得了无效的Google API调用许可?

Python 为什么我从AppEngine获得了无效的Google API调用许可?,python,google-app-engine,Python,Google App Engine,我正在尝试从AppEngine访问Google预测API,并按照这里的说明进行操作-- 这在部署到App Engine上时效果非常好。但是,相同的代码在本地devserver上失败,并出现以下错误 credentials = AppAssertionCredentials( scope='https://www.googleapis.com/auth/prediction') http = credentials.authorize(httplib2.Http(me

我正在尝试从AppEngine访问Google预测API,并按照这里的说明进行操作--

这在部署到App Engine上时效果非常好。但是,相同的代码在本地devserver上失败,并出现以下错误

credentials = AppAssertionCredentials(
              scope='https://www.googleapis.com/auth/prediction')
http = credentials.authorize(httplib2.Http(memcache))
service = build("prediction", "v1.5", http=http, developerKey=api_key)

ERROR    2012-12-28 03:48:53,084 client.py:461] Failed to retrieve access token: {
  "error" : "invalid_grant"
}
ERROR    2012-12-28 03:48:53,115 cgi.py:121] Traceback (most recent call last):
  File "/Users/gkedia/git/thirdgaze/main.py", line 83, in <module>
    service = build('prediction', 'v1.5', http=http, developerKey=api_key)
  File "/Users/gkedia/git/thirdgaze/apiclient/discovery.py", line 175, in build
    resp, content = http.request(requested_url)
  File "/Users/gkedia/git/thirdgaze/oauth2client/client.py", line 503, in new_request
    self._refresh(request_orig)
  File "/Users/gkedia/git/thirdgaze/oauth2client/client.py", line 412, in _refresh
    self._do_refresh_request(http_request)
  File "/Users/gkedia/git/thirdgaze/oauth2client/client.py", line 472, in _do_refresh_request
    raise AccessTokenRefreshError(error_msg)
AccessTokenRefreshError: invalid_grant
credentials=AppAssertionCredentials(
范围=https://www.googleapis.com/auth/prediction')
http=凭证.authorize(httplib2.http(memcache))
service=build(“预测”,“v1.5”,http=http,developerKey=api\u键)
错误2012-12-28 03:48:53084客户端。py:461]检索访问令牌失败:{
“错误”:“无效的授权”
}
错误2012-12-28 03:48:53115 cgi.py:121]回溯(最近一次呼叫上次):
文件“/Users/gmedia/git/thirdgaze/main.py”,第83行,在
service=build('prediction','v1.5',http=http,developerKey=api\u key)
文件“/Users/gmedia/git/thirdgaze/apiclient/discovery.py”,第175行,内部版本
resp,content=http.request(请求的url)
文件“/Users/gmedia/git/thirdgaze/oauth2client/client.py”,第503行,在新请求中
自我更新(请求源)
文件“/Users/gmedia/git/thirdgaze/oauth2client/client.py”,第412行,在刷新中
self.\u do\u刷新请求(http\u请求)
文件“/Users/gmedia/git/thirdgaze/oauth2client/client.py”,第472行,在“刷新”请求中
引发AccessTokenRefreshError(错误消息)
AccessTokenRefreshError:无效的\u授权
我注意到的一点是,对于完全相同的参数,
key\u name,signature=app\u identity.sign\u blob(base\u str)
在生产和本地机器上返回不同的签名


我的计算机的时间被正确同步,离线访问参数似乎还没有涉及。

app\u identity
更一般地说,服务帐户在
dev\u appserver
上不起作用。在本地测试时,为了获得与常规谷歌帐户相关联的访问令牌,您必须回退一个常规帐户

比如:

flow = OAuth2WebServerFlow(client_id='your_client_id',
                           client_secret='your_client_secret',
                           scope='https://www.googleapis.com/auth/prediction',
                           redirect_uri='http://localhost:8080/oauth2callback')
self.redirect(flow.step1_get_authorize_url())
然后在
/oauth2callback
处理程序中:

credentials = flow.step2_exchange(self.request.get('code'))
http = credentials.authorize(httplib2.Http(memcache))
service = build("prediction", "v1.5", http=http, developerKey=api_key)

您可以很容易地检测到您是在
dev\u appserver
上运行,还是在生产中使用
SERVER\u软件

在使用dev服务器的本地计算机上出现故障,还是在AppEngine上部署时出现故障?仅在本地计算机上出现故障。(带澄清的编辑问题)您是否知道
dev_appserver.py
是否仍然无法使用Google OAuth 2.0服务帐户,或者是否已经更新?什么是memcache和developerKey?