Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQLInterfaceError: Python type list cannot be converted

    @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')

it returns : MySQLInterfaceError: Python type list cannot be converted

like image 259
Ayman FATICH Avatar asked Aug 14 '26 16:08

Ayman FATICH


1 Answers

One solution is to convert list to string like this.

','.join(list)
like image 50
luky Avatar answered Aug 16 '26 04:08

luky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!