I have a weird error when I write a website with a jar and jar of mysql package.
Here is the error function code:
@app.route('/calendar/editeventtitle',methods=['POST'])
def editeventtitle():
if not session.get('logged_in'):
abort(401)
try:
id = request.form.get('id',type=int)
title = request.form['title']
color = request.form['color']
delete = request.form.get('delete')
except:
pass
conn = mysql.connect()
cursor = conn.cursor()
print(id,type(id))
if id and delete:
cursor.execute('delete from events where id = %d',id)
conn.commit()
flash('Event canceled!')
return redirect(url_for('calendar'))
elif id and title and color:
cursor.execute('update events set title = %s, color = %s where id = %d',(title,color,id))
conn.commit()
flash('Event updated!')
return redirect(url_for('calendar'))
When I post four variables to this page. I successfully receive them. And the result is print(id,type(id))as follows:
6 <class 'int'>
We see that this is really an integer, but when the code starts to update or delete data from db, here is the error message:
TypeError: format% d: number is required, not str
I don’t really know the reason = - =, can anyone help me? Thank.
PS: Python3.6.1, Flask 0.12.2, Flask-Mysql 1.4.0
source
share