GoogleAppEngine urlfetch 超时异常

发布于 2024-08-17 06:43:06 字数 1897 浏览 2 评论 0原文

有人在使用 GAE urlfetch 时遇到过以下异常吗?

      DownloadError: ApplicationError: 2 timed out

我正在尝试发送 HTTP POST 请求。就像这样:

      result = urlfetch.fetch('http://api.nathan.com:8080/Obj/',
                              method='POST',
                              payload=postdata,
                              deadline=10)

我尝试将截止日期设置为最大值(10 秒)。来自命令行的请求(使用curl或httplib2)大约需要一秒钟。

       nchong@almond ~ $ time curl
                         -d "<Obj><a>1</a><b>n</b></Obj>"
                         http://api.nathan.com:8080/Obj/
       agd1c2VyYXBpcgoLEgRTZXNzGAIM      #< key returned by call
       real 0m1.109s
       user 0m0.003s
       sys  0m0.009s

这是来自开发应用程序服务器的 curl 请求的输出(我正在使用 appengine-rest-server):

INFO     __init__.py:819] adding models from module __main__
INFO     __init__.py:867] added model Obj with type <class '__main__.Obj'>
INFO     dev_appserver.py:3243] "POST /Obj HTTP/1.1" 200 -
INFO     dev_appserver_index.py:205] Updating /path/to/index.yaml

这是我尝试使用 urlfetch 时的输出:

ERROR    __init__.py:388] ApplicationError: 2 timed out
Traceback (most recent call last):
  File "/path/to/webapp/__init__.py", line 507, in __call__
    handler.get(*groups)
  File "/path/to/myapp/main.py", line 62, in get
    result = urlfetch.fetch(...)
  File "/path/to/urlfetch.py", line 241, in fetch
    return rpc.get_result()
  File "/path/to/apiproxy_stub_map.py", line 501, in get_result
    return self.__get_result_hook(self)
  File "/path/to/urlfetch.py", line 325, in _get_fetch_result
    raise DownloadError(str(err))
DownloadError: ApplicationError: 2 timed out
INFO     dev_appserver.py:3243] "GET / HTTP/1.1" 500 -
INFO     dev_appserver.py:3243] "POST /Obj/ HTTP/1.1" 200 -

Has anyone got any experience with the following exception when using GAE urlfetch?

      DownloadError: ApplicationError: 2 timed out

I'm trying to send a HTTP POST request. Like so:

      result = urlfetch.fetch('http://api.nathan.com:8080/Obj/',
                              method='POST',
                              payload=postdata,
                              deadline=10)

I've tried setting deadline to the max (10 seconds). The request from the command line (using curl or httplib2) takes about a second.

       nchong@almond ~ $ time curl
                         -d "<Obj><a>1</a><b>n</b></Obj>"
                         http://api.nathan.com:8080/Obj/
       agd1c2VyYXBpcgoLEgRTZXNzGAIM      #< key returned by call
       real 0m1.109s
       user 0m0.003s
       sys  0m0.009s

Here's the output from the dev appserver for the curl request (I'm using appengine-rest-server):

INFO     __init__.py:819] adding models from module __main__
INFO     __init__.py:867] added model Obj with type <class '__main__.Obj'>
INFO     dev_appserver.py:3243] "POST /Obj HTTP/1.1" 200 -
INFO     dev_appserver_index.py:205] Updating /path/to/index.yaml

Here's the output when I try to use urlfetch:

ERROR    __init__.py:388] ApplicationError: 2 timed out
Traceback (most recent call last):
  File "/path/to/webapp/__init__.py", line 507, in __call__
    handler.get(*groups)
  File "/path/to/myapp/main.py", line 62, in get
    result = urlfetch.fetch(...)
  File "/path/to/urlfetch.py", line 241, in fetch
    return rpc.get_result()
  File "/path/to/apiproxy_stub_map.py", line 501, in get_result
    return self.__get_result_hook(self)
  File "/path/to/urlfetch.py", line 325, in _get_fetch_result
    raise DownloadError(str(err))
DownloadError: ApplicationError: 2 timed out
INFO     dev_appserver.py:3243] "GET / HTTP/1.1" 500 -
INFO     dev_appserver.py:3243] "POST /Obj/ HTTP/1.1" 200 -

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多孤肩上扛 2024-08-24 06:43:06

开发 Web 服务器是单线程的。您无法从在其中运行的应用程序向自身发出请求。尝试在不同端口上运行两个实例。

顺便说一句,一旦部署,这就不应该成为问题,因为实际的 AppEngine 服务器当然能够处理多个并发请求。

The development web server is single-threaded. You can not make a request from your application running inside it to itself. Try running two instances on different ports.

By the way, this should not be a problem once it is deployed, as the actual AppEngine server is of course able to handle multiple simultaneous requests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文