MySQLInterfaceError:无法转换Python类型列表

人气:353 发布:2022-10-16 标签: mysql python python-3.x flask mysql-python

问题描述

    @app.route('/upload', methods=["GET", "POST"])
def upload():
    if request.method == 'POST':

        file = request.files['upFile']
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))

        dir = app.config['UPLOAD_FOLDER']+ file.filename

        cmd  = "INSERT INTO posts (title, author, file, date, subject, field ) VALUES (%s, %s, %s, %s, %s, %s)"
        post = (request.form["title"], session['user_name'], dir, x, request.form["subject"], request.form.getlist("field[]"))
        crsr.execute(cmd, post)
        mydb.commit()

        return redirect(url_for('upload'))
    else:
        return render_template('upload.htm')

返回:MySQLInterfaceError:无法转换Python类型列表

推荐答案

一种解决方案是将列表转换为字符串,如下所示。

','.join(list)

427