Google Appengine URLFetch超时 - 任何最佳做法?

时间:2011-04-05 15:07:56

标签: python google-app-engine

python和appengine的新手。昨晚我玩了一个小玩具并且遇到了一些脚本超时。我知道你的上限为10秒。处理这个问题的最佳做法是什么?

修改

抱歉,本来应该更清楚。 URLFetch超时是我遇到的问题。默认设置为5秒,最大值为10

Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 636, in __call__
    handler.post(*groups)
  File "/base/data/home/apps/netlicense/3.349495357411133950/main.py", line 235, in post
    graph.put_wall_post(message=body, attachment=attch, profile_id=self.request.get("fbid"))
  File "/base/data/home/apps/netlicense/3.349495357411133950/facebook.py", line 149, in put_wall_post
    return self.put_object(profile_id, "feed", message=message, **attachment)
  File "/base/data/home/apps/netlicense/3.349495357411133950/facebook.py", line 131, in put_object
    return self.request(parent_object + "/" + connection_name, post_args=data)
  File "/base/data/home/apps/netlicense/3.349495357411133950/facebook.py", line 179, in request
    file = urllib2.urlopen(urlpath, post_data)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 124, in urlopen
    return _opener.open(url, data)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 381, in open
    response = self._open(req, data)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 399, in _open
    '_open', req)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 360, in _call_chain
    result = func(*args)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 1115, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 1080, in do_open
    r = h.getresponse()
  File "/base/python_runtime/python_dist/lib/python2.5/httplib.py", line 197, in getresponse
    self._allow_truncated, self._follow_redirects)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py", line 260, in fetch
    return rpc.get_result()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 592, in get_result
    return self.__get_result_hook(self)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py", line 361, in _get_fetch_result
    raise DeadlineExceededError(str(err))
DeadlineExceededError: ApplicationError: 5

1 个答案:

答案 0 :(得分:4)

您还没有告诉我们您的申请是做什么的,所以这里有一些通用的建议:

  1. 您可以使用此异常类google.appengine.api.urlfetch.DownloadError捕获超时exception,并轻轻提醒用户重试。
  2. Web请求运行时间最长为30秒;如果你要下载的内容相对较小,你可能会捕获异常,并在同一个Web请求中重新提交(仅一次)urlfetch。
  3. 如果离线工作不是您的应用程序的问题,您可以将Urlfetch调用移动到由Task Queue提供的工作人员任务;使用taskqueue API的一个优点是App Engine会自动重试Urlfetch任务,直到成功为止。