[英]loading excel file into pandas dataframe flask app running with mod_wsgi apache that user uploaded
I have a flask app where a user uploads files to an upload folder. 我有一个flask应用程序,用户可以在其中将文件上传到上传文件夹。 Then I want to take those files and read them into pandas dataframes for further processing.
然后,我想获取这些文件并将其读入pandas数据帧以进行进一步处理。 The process works fine using app.run() on my localhost.
使用我的本地主机上的app.run(),该过程可以正常工作。 I am trying to get it to work on aws with mod_wsgi and apache.
我正在尝试使其与mod_wsgi和apache一起在aws上工作。
@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
I get the error ValueError: Must explicitly set engine if not passing in buffer or path for io.
我收到错误
ValueError: Must explicitly set engine if not passing in buffer or path for io.
The file is uploaded to the upload folder correctly but obviously not fetched correctly into the f
variable. 该文件已正确上载到上载文件夹,但显然没有正确提取到
f
变量中。 The type of f is <class 'flask.wrappers.Response'>
and f.__dict__
returns 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}
When running on my localhost on my machine there was a .file attribute in the response, now response is empty. 在我的机器上的本地主机上运行时,响应中有一个.file属性,现在响应为空。 Printing folder_path gives
/var/www/html/cluster_app/data
which is the uploads folder. 打印folder_path会提供
/var/www/html/cluster_app/data
(即上载文件夹)。
I'm very green on flask/wsgi/apache. 我在烧瓶/ wsgi / apache上非常绿。 Would really appreciate some advice on how to access the file system in my code.
非常感谢在我的代码中有关如何访问文件系统的一些建议。
嗨,我建议您在此处查看关于上传文件的Flask文档,稍后再检查您的代码。
Instead of 代替
f=send_from_directory(folder_path,filename))
I use 我用
f = open(os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename))
to open the file. 打开文件。 I just assumed
send_from_directory
would work as it does when I used flask app.run()
on my localhost. 我只是假设
send_from_directory
可以像在本地主机上使用flask app.run()
。 I'd still like to know why send_from_directory
does not work. 我仍然想知道为什么
send_from_directory
不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.