Domanda

Qualcuno ha preso alcuna esperienza con la seguente eccezione quando si utilizza GAE UrlFetch?

      DownloadError: ApplicationError: 2 timed out

Sto cercando di inviare una richiesta HTTP POST. In questo modo:

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

Ho provato a fissare termine al massimo (10 secondi). La richiesta dalla linea di comando (usando arricciatura o httplib2) richiede circa un secondo.

       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

Ecco l'output del appserver dev per la richiesta ricciolo (sto usando AppEngine-resto-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

Ecco l'output quando provo ad usare 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 -
È stato utile?

Soluzione

Il server di sviluppo web è single-threaded. Non si può fare una richiesta dall'applicazione in esecuzione al suo interno a se stesso. Provate a lanciare due istanze su porte diverse.

Tra l'altro, questo non dovrebbe essere un problema una volta che è distribuito, come il server AppEngine reale è naturalmente in grado di gestire più richieste simultanee.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top