【问题标题】:DeadlineExceededError not caught in try catchDeadlineExceededError 未在 try catch 中捕获
【发布时间】:2015-12-10 16:31:05
【问题描述】:

我最近在 try-catch 块中包含了一个函数调用以捕获 all 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.

我正在使用带有 Python 的 Google App Engine。
我做错什么了 ?

【问题讨论】:

  • 原始错误有可能被 GIT 代码捕获并替换。添加另一个 except Exception 子句以捕获所有其他异常并显示异常详细信息以尝试识别到达您的代码的实际异常。
  • @DanCornilescu 谢谢。我添加了一个额外的except Exception 子句。我会等待异常再次发生。
  • 我使用:从 google.appengine.runtime import DeadlineExceededError
  • @voscausa 谢谢,但official Google page for exceptions thrown by URL Fetch 上没有提到。您是否能够在 URL Fetch 上捕获该异常属性?
  • 是的,可以使用几年。更多信息:cloud.google.com/appengine/articles/deadlineexceedederrors

标签: python python-2.7 google-app-engine google-identity-toolkit


【解决方案1】:

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

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)。

【讨论】:

  • 谢谢。我添加了一个额外的except Exception 子句。我会等待异常再次发生。
猜你喜欢
  • 1970-01-01
  • 2020-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多