如何在 Google App Engine 中设置 urlfetch 超时?
我试图让 Django(在 GAE 之上)从另一个 Web 服务获取数据。我经常遇到这样的错误:
应用程序错误:2 超时请求
方法:获取
异常类型:下载错误
异常值:ApplicationError:2 超时
异常位置:_get_fetch_result 第 325 行中的 /google_appengine/google/appengine/api/urlfetch.py
感觉好像只有 12 秒后才会超时(我不确定,但确实很短) 。
问题:如何设置更长的超时时间?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
鉴于这是一个 Python 问题,我想我应该为遇到此问题的任何人提供一个 Python 答案。
只需导入
urlfetch
,然后在代码中执行任何其他操作之前定义截止日期:Seeing as this is a
Python
question, I thought I'd provide a Python answer for anyone who comes across this problem.Just import
urlfetch
and then define a deadline before doing anything else in your code:您可以使用 的
deadline
参数进行设置获取函数。来自文档:编辑:看起来现在已经改变了。来自此处:
此页面列出了默认超时值:
You can set it using the
deadline
argument of the fetch function. From the docs:Edit: looks like this has changed now. From here:
And this page lists the default timeout values:
对于 Go,您可能想尝试下面的代码。
以下是如何使用它。
For Go, you might want to try below code.
Here is how to use it.
看似很短,但要知道GAE上的请求超时时间在30秒左右。由于您可能需要对 urlfetch 的响应执行一些操作,因此我认为超时不需要超过 10 秒。
It seems short but you have to know that the timeout of a request on GAE is around 30 seconds. As you probably need to do some operations on the response of your urlfetch, there's no need to have a timeout more than 10 seconds I think.