简体   繁体   中英

Error when formatting a String - ValueError: unsupported format character ',' (0x2c)

I'm formatting query strings to run on my database. I am getting a value error when I am trying to format using the % python string formatting method.

The specific error says ValueError: unsupported format character ',' (0x2c) at index where the , occurs after rate. So inside (locationId, userId, discountId, rate, <- that right there is what is causing the issue for some reason.

insertQuery = "INSERT INTO maprateinfo (locationId, userId, discountId, rate, customizedDiscount) VALUES (%i, %i, i%, %f, -1)" % (location, employee, locationDiscount, rate)

How can I fix this so the string formats properly? Using python 2.5.

It looks to me like you have a simple typo in your VALUES statement: i% should be %i .

Look into using a database layer that will handle doing all the necessary escaping for you (if you aren't already). Otherwise, little Bobby Tables will take over your database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM