如何在Google App Engine中为urlfetch设置超时? [英] How to set timeout for urlfetch in Google App Engine?
问题描述
我试图让Django(在GAE之上)从另一个Web服务中获取数据。我经常遇到这样的错误:
ApplicationError:2超时请求
方法:GET
请求网址: http:// localhost :8080 /
异常类型:DownloadError
异常值:ApplicationError:2超时
异常位置:_get_fetch_result中的/google_appengine/google/appengine/api/urlfetch.py第325行
感觉好像在12秒后才会超时(我不确定,但实际上很短)。
问题:如何设置更长的超时?
请求处理程序的最后期限最长可达60秒,任务队列和cron作业处理程序的最后期限可达最多60分钟。如果截止日期为无,截止日期设定为5秒。
编辑:看起来现在已经改变了。从这里:
您可以为请求设置最后期限,服务等待响应的时间最多。默认情况下,提取的截止日期为5秒。您可以使用
urlfetch.set_default_fetch_deadline()
函数调整请求的默认截止日期。
和此页面列出了默认超时值:
目前,Python运行时有几个名为DeadlineExceededError的错误: p>
google.appengine.runtime.DeadlineExceededError
:如果整体请求超时, 60秒后,或10分钟任务队列请求。
google.appengine.runtime.apiproxy_errors.DeadlineExceededError
:如果RPC超过了最后期限。这通常是5秒钟,但是可以使用'最后期限'选项为某些API设置。
google.appengine.api.urlfetch_errors.DeadlineExceededError
:如果URLFetch超时,则被调高。
I'm trying to have Django (on top of GAE) fetch data from another web service. I'm often hit with error like this:
ApplicationError: 2 timed out Request
Method: GET
Request URL:http://localhost:8080/
Exception Type: DownloadError
Exception Value: ApplicationError: 2 timed out
Exception Location: /google_appengine/google/appengine/api/urlfetch.py in _get_fetch_result, line 325
It feels as if it will time out only after 12 seconds (I'm not sure, but it's really short).
Question: how can I set a longer timeout?
You can set it using the deadline
argument of the fetch function. From the docs:
The deadline can be up to a maximum of 60 seconds for request handlers and 10 minutes for tasks queue and cron job handlers. If deadline is None, the deadline is set to 5 seconds.
Edit: looks like this has changed now. From here:
You can set a deadline for a request, the most amount of time the service will wait for a response. By default, the deadline for a fetch is 5 seconds. You can adjust the default deadline for requests using the
urlfetch.set_default_fetch_deadline()
function.
And this page lists the default timeout values:
Currently, there are several errors named DeadlineExceededError for the Python runtime:
google.appengine.runtime.DeadlineExceededError
: raised if the overall request times out, typically after 60 seconds, or 10 minutes for task queue requests.google.appengine.runtime.apiproxy_errors.DeadlineExceededError
: raised if an RPC exceeded its deadline. This is typically 5 seconds, but it is settable for some APIs using the 'deadline' option.google.appengine.api.urlfetch_errors.DeadlineExceededError
: raised if the URLFetch times out.
这篇关于如何在Google App Engine中为urlfetch设置超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!