【问题标题】:app_identity_service.GetAccessToken() required more quota than is availableapp_identity_service.GetAccessToken() 需要的配额多于可用配额
【发布时间】:2016-01-17 09:51:55
【问题描述】:

我正在使用应用引擎和大查询作为我网站的后端。每当用户单击时,我将它们登录到 bigquery 以便在当天晚些时候进行分析。我每天的点击量接近 75k。直到上周它都运行良好。这是我使用的代码。

    body = {"rows":[bodyFields]}

    credentials = appengine.AppAssertionCredentials(scope=BIGQUERY_SCOPE)
    http = credentials.authorize(httplib2.Http())
    bigquery = discovery.build('bigquery', 'v2', http=http)

    response = bigquery.tabledata().insertAll(
        projectId=PROJECT_ID,
        datasetId=BIGQUERY_DATASETID,
        tableId=BIGQUERY_TABLEID,
        body=body).execute()

现在突然间我超过了配额异常。我的应用程序是付费应用引擎实例。下面是我的异常的堆栈跟踪

Attempting refresh to obtain initial access_token

The API call app_identity_service.GetAccessToken() required more quota than is available.
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~projectname/bigqueryapi.387952303347375306/filename.py", line 1611, in post
    bigquery = discovery.build('bigquery', 'v2', http=http)
  File "/base/data/home/apps/s~projectname/bigqueryapi.387952303347375306/oauth2client/util.py", line 129, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/base/data/home/apps/s~projectname/bigqueryapi.387952303347375306/apiclient/discovery.py", line 198, in build
    resp, content = http.request(requested_url)
  File "/base/data/home/apps/s~projectname/bigqueryapi.387952303347375306/oauth2client/util.py", line 129, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/base/data/home/apps/s~projectname/bigqueryapi.387952303347375306/oauth2client/client.py", line 516, in new_request
    self._refresh(request_orig)
  File "/base/data/home/apps/s~projectname/bigqueryapi.387952303347375306/oauth2client/appengine.py", line 194, in _refresh
    scopes, service_account_id=self.service_account_id)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/app_identity/app_identity.py", line 589, in get_access_token
    scopes, service_account_id=service_account_id)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/app_identity/app_identity.py", line 547, in get_access_token_uncached
    return rpc.get_result()
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 613, in get_result
    return self.__get_result_hook(self)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/app_identity/app_identity.py", line 519, in get_access_token_result
    rpc.check_success()
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 579, in check_success
    self.__rpc.CheckSuccess()
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_rpc.py", line 134, in CheckSuccess
    raise self.exception
OverQuotaError: The API call app_identity_service.GetAccessToken() required more quota than is available.

我的流量并没有增加太多,处理程序被点击的次数也几乎与过去 2 个月的数据相同。那么为什么我会收到这个错误。

【问题讨论】:

    标签: python-2.7 google-app-engine google-bigquery google-authentication google-oauth


    【解决方案1】:

    为了确定您遇到配额错误的原因,您需要分享有关您的使用情况的更多详细信息。配额应每 24 小时重置一次。您知道错误出现需要多长时间以及您在该时间点成功提供了多少流量?

    您提到您“在当天晚些时候进行分析”,这表明您可能正在使用TaskQueue APIDeferred Tasks。这些任务可能由于其他原因而失败,retrying,这可能会很快耗尽您的配额。如果您使用的是 TaskQueues,您可以尝试调整 queue configuration and retry options

    另一种可以节省配额的方法是将您正在构建的 bigquery 发现服务保存到 Memcache API 之类的东西中,这样它就可以重复用于对 BigQuery 服务的多个请求。

    【讨论】:

    • 我使用大量的 TaskQueue 来调用我不想为用户阻塞时间的函数。任务队列是否吃光了 access_token 配额?
    • 我也觉得问题出在发现服务上。所以我重写了我的代码以使用 bigQuery 的 REST api 端点。问题仍然存在。另外据我了解,app engine API默认处理access_token的缓存
    • TaskQueue 的单独使用不会影响您的 access_token 配额,并且使用 TaskQueue 没有任何问题。 access_token 可能会被缓存,但很可能每个请求都会缓存它,并且每个任务都在单独的请求中运行。您是否有统计数据可以分享您每天运行的任务数以及成功运行的任务数?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 2021-03-15
    • 2012-08-09
    • 2020-07-28
    • 2017-09-25
    • 1970-01-01
    • 2020-04-01
    相关资源
    最近更新 更多