【问题标题】:GoogleAppEngine urlfetch timeout exceptionGoogleAppEngine urlfetch 超时异常
【发布时间】:2010-01-07 18:17:33
【问题描述】:

有没有人在使用 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 -

【问题讨论】:

  • 我目前的解决方法是将 urlfetch 调用包装在 try/except 传递块中。
  • 您是否能够查看此通话期间服务器上发生的情况?它是否正确处理有效负载并返回密钥? postdata 中的值是你认为的那样吗?
  • 嗨,Alex,服务器正在获取 POST 请求,它正在根据调用创建一个新的 Obj。
  • 然后完成响应了吗?
  • 是的!开发应用服务器是单线程的!它永远无法完成对自己的请求。

标签: google-app-engine exception urlfetch


【解决方案1】:

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

顺便说一下,一旦部署,这应该不是问题,因为实际的 AppEngine 服务器当然能够同时处理多个请求。

【讨论】:

  • 啊,这听起来像是一个很有希望的询问行。我会试试看,然后回复你。谢谢!
  • 这正是问题所在。将 urlfetch 的发送者和接收者拆分为单独的服务器解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 2012-10-30
  • 2011-05-06
  • 2020-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-18
  • 2022-01-18
相关资源
最近更新 更多