urlfetch DeadlineExceededError

时间:2014-01-07 22:22:11

标签: python google-app-engine rest httprequest urlfetch

我使用瓶子框架创建了一个REST API,它接收来自GAE的调用。调用此REST API后,它会进行一些计算并将输出作为zip文件发送到AMAZON S3服务器并将链接返回给GAE。一切正常,期待超时问题。我试图将urlfetch的截止日期调整为60秒,这并没有解决问题。我很感激任何建议。

GAE方:

response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=http_headers, deadline=60) 

Broser错误信息:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "D:\Dropbox\ubertool_src\przm5/przm5_output.py", line 22, in post
    przm5_obj = przm5_rest_model.przm5(args)
  File "D:\Dropbox\ubertool_src\przm5\przm5_rest_model.py", line 351, in __init__
    self.convertSoil1, self.convert1to3, self.convert2to3)
  File "D:\Dropbox\ubertool_src\przm5\przm5_rest_model.py", line 135, in get_jid
    response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=http_headers)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 270, in fetch
    return rpc.get_result()
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 612, in get_result
    return self.__get_result_hook(self)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 410, in _get_fetch_result
    'Deadline exceeded while waiting for HTTP response from URL: ' + url)
DeadlineExceededError: Deadline exceeded while waiting for HTTP response from URL: http://localhost:7777/my_model

REST服务器:

@route('/my_model', method='POST') 
@auth_basic(check)
def my_model():
    #run the model
    run_my model()

    #zip output files
    zout=zipfile.ZipFile("test.zip","w")
    for name in os.listdir(src1):
        zout.write(name)
    zout.close()

    ##upload file to S3
    conn = S3Connection(key, secretkey)
    bucket = Bucket(conn, 'przm5')
    k=Key(bucket)
    name1='PRZM5_'+name_temp+'.zip'
    k.key=name1

    ###All the above steps are fine####
    k.set_contents_from_filename('test.zip')
    link='https://s3.amazonaws.com/'+my_file_path
    return {'ff': ff}

run(host='localhost', port=7777, debug=True)

REST服务器的错误:

127.0.0.1 - - [07/Jan/2014 16:16:36] "POST /my_model HTTP/1.1" 200 1663
Traceback (most recent call last):
  File "C:\Python27\Lib\wsgiref\handlers.py", line 86, in run
    self.finish_response()
  File "C:\Python27\Lib\wsgiref\handlers.py", line 128, in finish_response
    self.write(data)
  File "C:\Python27\Lib\wsgiref\handlers.py", line 212, in write
    self.send_headers()
  File "C:\Python27\Lib\wsgiref\handlers.py", line 270, in send_headers
    self.send_preamble()
  File "C:\Python27\Lib\wsgiref\handlers.py", line 194, in send_preamble
    'Date: %s\r\n' % format_date_time(time.time())
  File "C:\Python27\Lib\socket.py", line 324, in write
    self.flush()
  File "C:\Python27\Lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
127.0.0.1 - - [07/Jan/2014 16:16:36] "POST /my_model HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 50953)
Traceback (most recent call last):
  File "C:\Python27\Lib\SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\Lib\SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\Lib\SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\Lib\SocketServer.py", line 651, in __init__
    self.finish()
  File "C:\Python27\Lib\SocketServer.py", line 710, in finish
    self.wfile.close()
  File "C:\Python27\Lib\socket.py", line 279, in close
    self.flush()
  File "C:\Python27\Lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine

1 个答案:

答案 0 :(得分:1)

截止日期是一个最大值,一旦达到它就会失败。

失败了
  

等待HTTP响应时超过截止日期

因此,您应该尝试捕获该异常并再试一次。

如果整个操作不能在60秒内完成,那么就没有别的办法了,GAE的一个硬限制是HTTP请求不能超过60秒。