将excel文件加载到pandas dataframe使用mod_wsgi运行Apache应用程序运行的应用程序用户上传的apache
我有一个应用程序,用户上传文件到上传文件夹。然后,我想将这些文件读入熊猫数据框中作进一步处理。该进程在我的本地主机上使用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很绿。真的很感谢一些关于如何访问我的代码中的文件系统的建议。
而不是
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
不起作用。
试试这个'excel_file = pandas.ExcelFile(f,engine ='xlrd')'。 – shivsn
谢谢,我试过这个,但得到相同的错误 – clurhur
我认为你应该提到的文件路径像一个URL像'excel_file = pandas.ExcelFile(file:// path/to/your/file)'。 – shivsn