Мне удалось получить файл Excel (xlsx) из каталога загрузки сервера, и теперь мне нужно обработать его в pandas фрейм данных.
В настоящее время я получаю следующую ошибку: ValueError: Неверный путь к файлу или тип объекта буфера:
Я проверил путь к файлу и смог успешно загрузить файл Excel для браузера в качестве вложения, поэтому я думаю, что это не проблема .. Я думаю, что проблема заключается в преобразовании его в фрейм данных.
@app.route('/Results/<filename>/', methods=['GET', 'POST'])
def processing(filename):
if request.method == 'POST':
retrieve_file = send_from_directory(app.config['UPLOAD_FOLDER'],filename=filename, as_attachment=False)
Input_data_dataframe = pd.read_excel(retrieve_file) #converts uploaded file to a dataframe astype(int)
return render_template('results.html',filename=filename,tables=[Input_data_dataframe.to_html(classes=["table table-dark table-hover"], header="true", index=False,)])
return render_template('Set_parameters.html')
Это информация трассировки:
2020-04-26 18:25:58,278: Error running WSGI application
2020-04-26 18:25:58,285: ValueError: Invalid file path or buffer object type: <class 'flask.wrappers.Response'>
2020-04-26 18:25:58,285: File "/usr/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
2020-04-26 18:25:58,285: return self.wsgi_app(environ, start_response)
2020-04-26 18:25:58,285:
2020-04-26 18:25:58,285: File "/usr/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
2020-04-26 18:25:58,286: response = self.handle_exception(e)
2020-04-26 18:25:58,286:
2020-04-26 18:25:58,286: File "/usr/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
2020-04-26 18:25:58,286: reraise(exc_type, exc_value, tb)
2020-04-26 18:25:58,286:
2020-04-26 18:25:58,287: File "/usr/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
2020-04-26 18:25:58,287: raise value
2020-04-26 18:25:58,287:
2020-04-26 18:25:58,287: File "/usr/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
2020-04-26 18:25:58,287: response = self.full_dispatch_request()
2020-04-26 18:25:58,287:
2020-04-26 18:25:58,288: File "/usr/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
2020-04-26 18:25:58,288: rv = self.handle_user_exception(e)
2020-04-26 18:25:58,288:
2020-04-26 18:25:58,288: File "/usr/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
2020-04-26 18:25:58,288: reraise(exc_type, exc_value, tb)
2020-04-26 18:25:58,289:
2020-04-26 18:25:58,289: File "/usr/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
2020-04-26 18:25:58,289: raise value
2020-04-26 18:25:58,289:
2020-04-26 18:25:58,289: File "/usr/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
2020-04-26 18:25:58,289: rv = self.dispatch_request()
2020-04-26 18:25:58,290:
2020-04-26 18:25:58,290: File "/usr/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
2020-04-26 18:25:58,290: return self.view_functions[rule.endpoint](**req.view_args)
2020-04-26 18:25:58,290:
2020-04-26 18:25:58,290: File "/home/morganprott/mysite/flask_app.py", line 50, in processing
2020-04-26 18:25:58,290: Input_data_dataframe = pd.read_excel(retrievedfile) #converts uploaded file to a dataframe astype(int)
2020-04-26 18:25:58,291:
2020-04-26 18:25:58,291: File "/usr/lib/python3.7/site-packages/pandas/util/_decorators.py", line 208, in wrapper
2020-04-26 18:25:58,291: return func(*args, **kwargs)
2020-04-26 18:25:58,291:
2020-04-26 18:25:58,291: File "/usr/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 310, in read_excel
2020-04-26 18:25:58,292: io = ExcelFile(io, engine=engine)
2020-04-26 18:25:58,292:
2020-04-26 18:25:58,292: File "/usr/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 819, in __init__
2020-04-26 18:25:58,292: self._reader = self._engines[engine](self._io)
2020-04-26 18:25:58,292:
2020-04-26 18:25:58,292: File "/usr/lib/python3.7/site-packages/pandas/io/excel/_xlrd.py", line 21, in __init__
2020-04-26 18:25:58,293: super().__init__(filepath_or_buffer)
2020-04-26 18:25:58,293:
2020-04-26 18:25:58,293: File "/usr/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 350, in __init__
2020-04-26 18:25:58,293: filepath_or_buffer, _, _, _ = get_filepath_or_buffer(filepath_or_buffer)
2020-04-26 18:25:58,293:
2020-04-26 18:25:58,293: File "/usr/lib/python3.7/site-packages/pandas/io/common.py", line 224, in get_filepath_or_buffer
2020-04-26 18:25:58,294: raise ValueError(msg.format(_type=type(filepath_or_buffer)))