GoogleAppEngine网址抓取超时异常
-
19-09-2019 - |
题
有没有人有与下面的异常任何经验使用GAE网址抓取的时候?
DownloadError: ApplicationError: 2 timed out
我想要发送HTTP POST请求。像这样:
result = urlfetch.fetch('http://api.nathan.com:8080/Obj/',
method='POST',
payload=postdata,
deadline=10)
我试图设置期限到最大(10秒)。在命令行的请求(使用卷曲或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
下面是从开发应用程序服务器的卷曲请求的输出(我使用应用服务引擎静止服务器):
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 -
解决方案
开发网络服务器是单线程。你不能让你的应用程序中运行它本身的请求。尝试不同的端口上运行的两个实例。
顺便说一句,这不应该,一旦它被部署是一个问题,因为实际的AppEngine上的服务器当然能够同时处理多个请求。
不隶属于 StackOverflow