GoogleAppEngine urlfetch 시간 초과 예외
-
19-09-2019 - |
문제
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 사용)은 약 1초 정도 걸립니다.
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
컬 요청에 대한 dev appserver의 출력은 다음과 같습니다(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 -
해결책
개발 웹 서버는 단일 스레드입니다.내부에서 실행 중인 애플리케이션에서 자체적으로 요청할 수는 없습니다.서로 다른 포트에서 두 개의 인스턴스를 실행해 보세요.
그런데 실제 AppEngine 서버는 물론 여러 개의 동시 요청을 처리할 수 있으므로 일단 배포되면 문제가 되지 않습니다.
제휴하지 않습니다 StackOverflow