我有一個應用程序,用戶上傳文件到上傳文件夾。然後,我想將這些文件讀入熊貓數據框中作進一步處理。該進程在我的本地主機上使用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很綠。真的很感謝一些關於如何訪問我的代碼中的文件系統的建議。
試試這個'excel_file = pandas.ExcelFile(f,engine ='xlrd')'。 – shivsn
謝謝,我試過這個,但得到相同的錯誤 – clurhur
我認爲你應該提到的文件路徑像一個URL像'excel_file = pandas.ExcelFile(file:// path/to/your/file)'。 – shivsn