Google App Engine / Drive SDK:捕获大量HTTP截止日期异常

时间:2013-06-07 21:24:01

标签: python google-app-engine google-api google-drive-api

我们的应用程序部署在Google App Engine,Python运行时(2.7)上并且正在使用Drive API。由于超出截止日期,在不同的终端(云端硬盘,OAuth等)上,越来越多的人抓住HTTPException

我们已经实现了5次尝试的指数退避机制。我们的应用程序越来越多地达到了这个限制(例如今天早上我们有很多例外)。

这个问题可能是什么原因?是否可以增加超时延迟?

感谢您的帮助。

这是一个完整的堆栈跟踪(OAuth2 API):

2013-06-07 21:11:10,851 ERROR An error occurred : Deadline exceeded while waiting for HTTP response from URL: https://accounts.google.com/o/oauth2/token
Traceback (most recent call last):
  File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~unishared-gae/production.367909734400765242/main.py", line 733, in get
    creds = self.GetCodeCredentials() or self.GetSessionCredentials()
  File "/base/data/home/apps/s~unishared-gae/production.367909734400765242/main.py", line 301, in GetCodeCredentials
    creds = oauth_flow.step2_exchange(code)
  File "lib/oauth2client/util.py", line 128, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "lib/oauth2client/client.py", line 1283, in step2_exchange
    headers=headers)
  File "lib/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "lib/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "lib/httplib2/__init__.py", line 1286, in _conn_request
    response = conn.getresponse()
  File "/python27_runtime/python27_dist/lib/python2.7/httplib.py", line 500, in getresponse
    raise HTTPException(str(e))

1 个答案:

答案 0 :(得分:1)

2011年发布的

This博客文章讨论了如何使用元类而不是使用装饰器捕获DeadlineExceededError。我不确定这个指南或解决了你,但给你一个可能有帮助的想法。

from google.appengine.api import mail
from google.appengine.ext.deferred import defer
from google.appengine.ext.webapp import RequestHandler
from google.appengine.runtime import DeadlineExceededError
import sys
from traceback import format_exception
from SOME_APP_SPECIFIC_LIBRARY import serve_500
from LAST_POST import email_admins

class DecorateHttpVerbsMetaclass(type):

    def __new__(cls, name, bases, cls_attr):
        verbs = ['get', 'post', 'put', 'delete']
        for verb in verbs:
            if verb in cls_attr and isinstance(cls_attr[verb], function):
                cls_attr[verb] = deadline_decorator(cls_attr[verb])

        return super(DecorateHttpVerbsMetaclass, cls).__new__(cls, name,
                                                              bases, cls_attr)

class ExtendedHandler(RequestHandler):
    __metaclass__ = DecorateHttpVerbsMetaclass

    def handle_exception(self, exception, debug_mode):
        traceback_info = ''.join(format_exception(*sys.exc_info()))
        email_admins(traceback_info, defer_now=True)

        serve_500(self)