Google App Engine / Drive SDK:捕捉很多HTTP Deadline异常 [英] Google App Engine / Drive SDK: catching a lot HTTP Deadline exceptions

查看:111
本文介绍了Google App Engine / Drive SDK:捕捉很多HTTP Deadline异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序部署在Google App Engine,Python运行时(2.7)并正在使用Drive API。越来越多,它捕捉到 HTTPException ,因为超过了截止日期,在不同的端点上(Drive,OAuth等)

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



这个问题的起源可能是什么?是否有可能增加超时延迟?



感谢您的帮助。
$ b

以下是完整的堆栈跟踪(OAuth2 API):

  2013-06-07 21:11:10,851错误发生了一个错误:在等待来自URL的HTTP响应时超出了截止日期:https://accounts.google .com / o / oauth2 /令牌
Traceback(最近一次调用最后一次):
文件/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py,第545行,发送
返回方法(* args,** kwargs)
文件/base/data/home/apps/s~unishared-gae/production.367909734400765242/main.py,第733行,获取
creds = self.GetCodeCredentials()或self.GetSessionCredentials()
文件/base/data/home/apps/s~unishared-gae/production.367909734400765242/main.py,行301,在GetCodeCredentials
creds = oauth_flow.step2_exchange(代码)
位置位置包装文件lib / oauth2client / util.py,第128行
返回包装(* args,** kwargs)
在步骤2_中的文件lib / oauth2client / client.py,行1283交换
headers =头文件)
请求
(response,content)= self._request(conn,authority,uri,request_uri)中的文件lib / httplib2 / __ init__.py,第1570行,方法,主体,标题,重定向,cachekey)
在_request
(response,content)= self._conn_request(conn,request_uri,方法1317)中的文件lib / httplib2 / __ init__.py ,body,headers)
在_conn_request
response = conn.getresponse()
文件中的lib / httplib2 / __ init__.py,第1286行文件/ python27_runtime / python27_dist / lib / python2 .7 / httplib.py,第500行,在getresponse中
raise HTTPException(str(e))


解决方案

2011年发布的这篇博客文章讨论了如何用metaclass而不是使用装饰器来捕获DeadlineExceededError。我不确定这个指南或解决了你,但给了你一个可能有用的主意。

  from google.appengine.api从google.appengine.ext.deferred导入邮件
从google.appengine.ext.webapp导入延迟
从google.appengine.runtime导入RequestHandler
import DeadlineExceededError
导入sys
from traceback import format_exception $ b $ from SOME_APP_SPECIFIC_LIBRARY import_service_500
from LAST_POST import email_admins
$ b $ class DecorateHttpVerbsMetaclass(type):

def __new __(cls,name ,base,cls_attr):
动词= ['get','post','put','delete']
用于动词的动词:
如果动词在cls_attr和isinstance(cls_attr [动词],函数):
cls_attr [动词] = deadline_decorator(cls_attr [动词])

返回超级(DecorateHttpVerbsMetaclass,cls).__新__(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)


Our app is deployed on the Google App Engine, Python runtime (2.7) and is consuming the Drive API. More and more it catches HTTPException because of an exceeded deadline, on different endpoints (Drive, OAuth, etc.)

We have implemented an exponential back-off mechanism with 5 tries. Our app is more and more reaching this limit (this morning for example we had a lot of these exceptions).

What could be the origin of this issues? Is it possible to increase the timeout delay?

Thanks for your help.

Here's a full stacktrace (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))

解决方案

This blog post published in 2011 talks about how to catch DeadlineExceededError with metaclass instead of using decorators. I do not sure this guides or solves you, but gives you a idea that may be helpful.

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)

这篇关于Google App Engine / Drive SDK:捕捉很多HTTP Deadline异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆