繁体   English   中英

在尝试捕获中未捕获DeadlineExceededError

[英]DeadlineExceededError not caught in try catch

我最近在try-catch块中包含了一个函数调用,以捕获所有URL Fetch异常,但根据下面的日志,未捕获到该异常。

from google.appengine.api import urlfetch_errors 
:: 
:: 
try: 
    gitkit_user     = gitkit_instance.VerifyGitkitToken (self.request.cookies['gtoken']) 
except ( urlfetch_errors.DeadlineExceededError, urlfetch_errors.ConnectionClosedError, urlfetch_errors.DNSLookupFailedError, urlfetch_errors.DownloadError, urlfetch_errors.Error, urlfetch_errors.InternalTransientError, urlfetch_errors.InvalidMethodError, urlfetch_errors.InvalidURLError, urlfetch_errors.MalformedReplyError, urlfetch_errors.PayloadTooLargeError, urlfetch_errors.ResponseTooLargeError, urlfetch_errors.SSLCertificateError, urlfetch_errors.TooManyRedirectsError ): 

    logging.error ("Exception occurred while executing gitkit_instance.VerifyGitkitToken (). \nDetails: "+traceback.format_exc ()) 

错误日志,包括跟踪

The API call urlfetch.Fetch() took too long to respond and was cancelled.
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/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 1057, in add_context_wrapper
    return synctaskletfunc(*args, **kwds)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 1038, in synctasklet_wrapper
    return taskletfunc(*args, **kwds).get_result()
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 1011, in tasklet_wrapper
    result = func(*args, **kwds)
  File "/base/data/home/apps/s~myapp/1.389163610985502634/main_v3.py", line 29956, in get
    gitkit_user     = gitkit_instance.VerifyGitkitToken (self.request.cookies['gtoken'])
  File "/base/data/home/apps/s~myapp/1.389163610985502634/gitkitclient.py", line 216, in VerifyGitkitToken
    certs = self.rpc_helper.GetPublicCert()
  File "/base/data/home/apps/s~myapp/1.389163610985502634/rpchelper.py", line 159, in GetPublicCert
    resp, content = self.http.request(cert_url, headers=headers)
  File "/base/data/home/apps/s~myapp/1.389163610985502634/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/base/data/home/apps/s~myapp/1.389163610985502634/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/base/data/home/apps/s~myapp/1.389163610985502634/httplib2/__init__.py", line 1286, in _conn_request
    response = conn.getresponse()
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/gae_override/httplib.py", line 522, in getresponse
    **extra_kwargs)
  File "/base/data/home/apps/s~myapp/1.389163610985502634/httplib2/__init__.py", line 1089, in fixed_fetch
    validate_certificate=validate_certificate)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/urlfetch.py", line 271, in fetch
    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/urlfetch.py", line 378, in _get_fetch_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
DeadlineExceededError: The API call urlfetch.Fetch() took too long to respond and was cancelled.

我正在将Google App Engine与Python结合使用。
我做错了什么 ?

这可能无法完全回答您的问题,但是为什么不这样做呢?

try: 
    gitkit_user = gitkit_instance.VerifyGitkitToken (self.request.cookies['gtoken']) 
except Exception as e:
    logging.error ("Exception occurred while executing gitkit_instance.VerifyGitkitToken (). \nDetails: " + e) 

错误将被捕获,错误类型将被打印(e)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM