pymysql: TypeError: percent d format: a number is required, not str || Solved

My situation is this:

num = cursor.execute("insert into info (name,age) values(%s,%d)",('lisi',20))

This is the above statement, because the age in the table is int, so you should use% d, but such an error occurs.

At this time, we changed all the formats to% s and quoted 20:

as follows:

num = cursor.execute("insert into info (name,age) values(%s,%s)",('lisi','20'))

All the problems have been solved, and they can be successfully inserted into the database after submission.

So we can always use% s to match in database statements.

Published 124 original articles · Like 24 · Visits 10,000+

Guess you like

Origin blog.csdn.net/qq_42214953/article/details/105449618