It has nothing to do with special characters. You're making the same mistake as so many before you; the %s
is not being used the same as the old-style string formatting. Do not use string formatting to insert parameters into queries - this is open to SQL Injection. It is unfortunate that the DB API also specifies %s
as valid: https://www.python.org/dev/peps/pep-0249/#paramstyle. See also MySQL parameterized queries
Now there's another issue:
query="insert into mytable values ('%s','%s','%s','%s',%s,'%s')"
Count the %s
. There's 6. Now count:
(str(cr),str(cs),str(srv),str(cl),recipe["total_time"],image,name)
That's a tuple of 7 values. So how do you expect that to work with 6 placeholders? If recipes
is a pd.Series
then you have even more issues, but hopefully it's not.
My guessed answer:
query="INSERT INTO mytable VALUES ('%s', '%s', '%s', '%s', '%s, '%s', '%s')"
value=(str(cr), str(cs), str(srv), str(cl), recipe["total_time"], image, name)
cursor.execute(query, value)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…