2016-06-07 56 views
0

我有一個應用程序,用戶上傳文件到上傳文件夾。然後,我想將這些文件讀入熊貓數據框中作進一步處理。該進程在我的本地主機上使用app.run()正常工作。我試圖讓它與mod_wsgi和apache一起工作。將excel文件加載到pandas dataframe使用mod_wsgi運行Apache應用程序運行的應用程序用戶上傳的apache

@app.route('/uploader', methods=['POST']) 
    def upload_file(): 
     if request.method == 'POST': 
      filenames=[] 
      uploaded_files = request.files.getlist("file[]") 
      file.save(os.path.join(app.root_path,app.config['UPLOAD_FOLDER'], filename)) 
      filenames.append(filename) 
     plotfiles=parse_all(filenames) 

    def parse_all(filenames): 
     folder_path=os.path.join(app.root_path, app.config['UPLOAD_FOLDER']) 
     for f in filenames: 
      f=send_from_directory(folder_path,filename)) 
      excel_file=pandas.ExcelFile(f) 
      #do more stuff 

我得到的錯誤ValueError: Must explicitly set engine if not passing in buffer or path for io.

的文件正確上傳到上傳文件夾,但顯然不是正確提取到f變量。 F型是<class 'flask.wrappers.Response'>f.__dict__回報

{'_on_close': [], 'response': [], 'headers': Headers([('X-Sendfile', u'/var/www/html/cluster_app/data/filename.xlsx'), ('Content-Length', u'82668'), ('Content-Type', u'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'), ('Cache-Control', u'public, max-age=43200'), ('Expires', u'Tue, 07 Jun 2016 22:59:11 GMT'), ('ETag', u'"1465297151.54-82668-755509703"')]), '_status_code': 200, '_status': '200 OK', 'direct_passthrough': True}

當在我的本地我的機器上有一個在響應.file屬性運行,現在的反應是空的。打印文件夾路徑給出/var/www/html/cluster_app/data這是上傳文件夾。

我對燒瓶/ wsgi/apache很綠。真的很感謝一些關於如何訪問我的代碼中的文件系統的建議。

+0

試試這個'excel_file = pandas.ExcelFile(f,engine ='xlrd')'。 – shivsn

+0

謝謝,我試過這個,但得到相同的錯誤 – clurhur

+0

我認爲你應該提到的文件路徑像一個URL像'excel_file = pandas.ExcelFile(file:// path/to/your/file)'。 – shivsn

回答

0

而不是

f=send_from_directory(folder_path,filename))

我用

f = open(os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename))

打開該文件。我只是假設send_from_directory會像我在本地主機上使用燒瓶app.run()時那樣工作。我仍然想知道爲什麼send_from_directory不起作用。

0

嗨我建議你檢查關於上傳文件的燒瓶文檔here,稍後重新檢查你的代碼。

相關問題