创建cgi.FieldStorage对象时出现超时错误

时间:2009-09-13 14:53:41

标签: python cgi cherrypy

嘿,任何关于我在这里得到的超时错误的想法:

错误追踪:

  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/_cprequest.py", line 606, in respond                                                        
    cherrypy.response.body = self.handler()                                                                                                                      
  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/_cpdispatch.py", line 25, in __call__                                                       
    return self.callable(*self.args, **self.kwargs)                                                                                                              
  File "sync_server.py", line 853, in put_file                                                                                                                   
    return RequestController_v1_0.put_file(self, *args, **kw)                                                                                                    
  File "sync_server.py", line 409, in put_file                                                                                                                   
    saved_path, tgt_path, root_folder = self._save_file(client_id, theFile)                                                                                      
  File "sync_server.py", line 404, in _save_file                                                                                                                 
    saved_path, tgt_path, root_folder = get_posted_file(cherrypy.request, 'theFile', staging_path)                                                               
  File "sync_server.py", line 1031, in get_posted_file                                                                                                           
    , keep_blank_values=True)                                                                                                                                    
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 496, in __init__                                                                                     
    self.read_multi(environ, keep_blank_values, strict_parsing)                                                                                                  
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 620, in read_multi                                                                                   
    environ, keep_blank_values, strict_parsing)                                                                                                                  
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 498, in __init__                                                                                     
    self.read_single()                                                                                                                                           
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 635, in read_single                                                                                  
    self.read_lines()                                                                                                                                            
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 657, in read_lines                                                                                   
    self.read_lines_to_outerboundary()                                                                                                                           
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 685, in read_lines_to_outerboundary                                                                  
    line = self.fp.readline(1<<16)                                                                                                                               
  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/wsgiserver/__init__.py", line 206, in readline                                              
    data = self.rfile.readline(size)                                                                                                                             
  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/wsgiserver/__init__.py", line 868, in readline                                              
    data = self.recv(self._rbufsize)                                                                                                                             
  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/wsgiserver/__init__.py", line 747, in recv                                                  
    return self._sock.recv(size)                                                                                                                                 
timeout: timed out                        

以下是被调用的代码:

    def get_posted_file(request, form_field_name, tgt_folder, tgt_fname=None):                                                                                       
        logger.debug('get_posted_file: %s' % request.headers['Last-Modified'])                                                                                       

        lowerHeaderMap = {}                                                                                                                                          
        for key, value in request.headers.items():                                                                                                                   
            lowerHeaderMap[key.lower()] = value                                                                                                                      

--->    dataDict = TmpFieldStorage(fp=request.rfile, headers=lowerHeaderMap, environ={'REQUEST_METHOD':'POST'}                                                       
                                   , keep_blank_values=True)                                                                                                         

class TmpFieldStorage(cgi.FieldStorage):                                                                                                                         
    """                                                                                                                                                          
    Use a named temporary file to allow creation of hard link to final destination                                                                               
    """                                                                                                                                                          
    def make_file(self, binary=None):                                                                                                                            
        tmp_folder = os.path.join(get_filer_root(cherrypy.request.login), 'sync_tmp')                                                                            
        if not os.path.exists(tmp_folder):                                                                                                                       
            os.makedirs(tmp_folder)                                                                                                                              
        return tempfile.NamedTemporaryFile(dir=tmp_folder)       

1 个答案:

答案 0 :(得分:0)

  

environ = {'REQUEST_METHOD':'POST'}

这似乎相当不足environ。 CGI规范需要更多的环境变量,其中一些cgi模块将需要。

特别是没有CONTENT_LENGTH标头。没有它,cgi默认为读取流的全部内容直到EOF。但由于它(可能)是一个网络流而不是一个文件,所以没有EOF(或者至少没有一个EOF直接在提交结束时),所以表单阅读器将坐在那里等待更多的输入永远不会来。超时。