2010-01-07 82 views
11

有没有人在使用GAE urlfetch时遇到以下异常?GoogleAppEngine 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)需要大约一秒钟的时间。

 [email protected] ~ $ 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 

下面是开发应用程序服务器输出为卷曲请求(我使用AppEngine上休息服务器):

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 

这里的输出,当我尝试使用网址抓取:

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 - 
+1

我目前的解决方法是将urlfetch调用包装在try/except传递块中。 – nafe 2010-01-07 18:19:39

+0

您是否能够在此通话期间查看服务器上发生的情况?它是否正确地处理有效载荷并返回密钥? postdata中的价值是你认为的吗? – 2010-01-07 18:25:59

+0

嗨亚历克斯,服务器正在获取POST请求,它正在创建一个新的基于通话的对象。 – nafe 2010-01-07 19:02:23

回答

12

开发Web服务器是单线程的。你不能从自己运行的应用程序发出请求。尝试在不同端口上运行两个实例。

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

+0

啊,这听起来像一个非常有前途的调查线。我会尝试一下并回复你。谢谢! – nafe 2010-01-07 23:40:40

+2

这个_really_ shoudl在文档中。 – bobobobo 2010-01-15 04:24:42

+0

这正是这个问题。将urlfetch的发送者和接收者分割成不同的服务器解决了我的问题。 – nafe 2010-01-15 04:26:36