我对flask完全陌生(事实上我今天早上才开始),到目前为止,我只实现了一个基本的上传功能(取自flask文档)。文件上传工作正常,但我似乎不知道如何将文件传递到另一种方法(挖掘)。当我这样做时,我总是会收到错误消息:AttributeError:“\u io.BytesIO”对象没有属性“lower”。接受任何形式的帮助对我来说都是非常重要的!提前谢谢大家
def mining(xes):
log = xes_importer.apply(xes)
tracefilter_log_pos = attributes_filter.apply_events(log, ["complete"], parameters={attributes_filter.Parameters.ATTRIBUTE_KEY: "lifecycle:transition", attributes_filter.Parameters.POSITIVE: True})
variants = pm4py.get_variants_as_tuples(tracefilter_log_pos)
Alpha(variants.keys())
Heuristic(variants.keys(), 1, 0.5)
UPLOAD_FOLDER = '/Users/jenny/processmining_lab/uploads'
ALLOWED_EXTENSIONS = set(['xes'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# If the user does not select a file, the browser submits an
# empty file without a filename.
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return mining(file)
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
'''
这取决于
mining
函数的外观file
是一个^{所以(没有看到)你的
mining
函数应该是这样的:你提到的
AttributeError
听起来像是试图运行某个不返回字符串的lower
方法作为旁注:很难知道代码中的位置,因为您从未发布过完整的回溯,所以没有发生此异常
编辑
看起来您正在使用PM4Py,此文档对此声明:
因此,您需要向挖掘函数实际传递一个文件路径
我建议将主代码更改为:
相关问题 更多 >
编程相关推荐