5
常常GAE不能上傳文件,我收到以下錯誤:如何在出現錯誤的情況下重試urlfetch.fetch幾次?
ApplicationError: 2
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/picasa2vkontakte/1.348093606241250361/picasa2vkontakte.py", line 109, in post
headers=headers
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 355, in _get_fetch_result
raise DownloadError(str(err))
DownloadError: ApplicationError: 2
我應該如何在這樣的錯誤的情況下進行重試?
try:
result = urlfetch.fetch(url=self.request.get('upload_url'),
payload=''.join(data),
method=urlfetch.POST,
headers=headers
)
except DownloadError:
# how to retry 2 more times?
# and how to verify result here?
謝謝,@德魯西爾斯。檢查'status_code'是否正確:'if result.status_code == 200:break'? – 2011-05-04 12:34:38
應該沒有必要。如果提取返回失敗代碼(404,500),則將引發異常,並且try塊中的任何其他內容都不會運行,包括中斷。 – 2011-05-04 12:49:19