应用程序正试图在服务帐户的帮助下使用googleapps目录API获取用户信息列表(>;200个用户)。你知道吗
if not memcache.get('directory_service'):
f = file(KEY_FILE, 'r')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
service_email,
key,
'https://www.googleapis.com/auth/admin.directory.user',
sub=GoogleAppAdminEmail)
http_auth = credentials.authorize(Http())
directory_service = build('admin', 'directory_v1', http=http_auth)
memcache.set('directory_service', directory_service, 60 * 60 * 2)
else:
directory_service = memcache.get('directory_service')
user = directory_service.users().get(userKey=username).execute()
我认为最好将directory_service
对象保存在memcache中,以减少执行时间,这样第二个请求之后的应用程序将从memcache获取对象。你知道吗
但是我在实现Memcache之后得到了HttpError 401
。你知道吗
File "C:\Users\test\appcode\oauth2client\util.py", line 135, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\test\appcode\googleapiclient\http.py", line 723, in execute
raise HttpError(resp, content, uri=self.uri)
HttpError: <HttpError 401 when requesting https://www.googleapis.com/admin/directory/v1/users/username%40mydomain.com?alt=json returned "Login Required">
处理这种情况的有效方法是什么?你知道吗
对存储
directory_service
对象没有什么兴趣,因为它是在不调用外部api的情况下创建的。你知道吗您应该存储的是
http_auth
对象,因为这个对象的生成成本很高。你知道吗此外,每秒只能请求服务帐户中的令牌一定次数。我不认为确切的限制在某个地方有记录,但是如果您试图同时从同一个服务帐户生成太多的令牌,您将得到一个
Rate limit exceeded
错误。你知道吗好的做法是将令牌存储在一些共享存储服务中。它可以是memcache或数据存储。googleapi客户机附带了您应该使用的an App Engine specific ^{} class 。它由数据存储支持,并使用Memcache作为可选的缓存层。你知道吗
相关问题 更多 >
编程相关推荐