简体   繁体   English

格式化字符串时出错-ValueError:不支持的格式字符','(0x2c)

[英]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. 尝试使用%python字符串格式化方法进行格式化时,出现值错误。

The specific error says ValueError: unsupported format character ',' (0x2c) at index where the , occurs after rate. 特定错误说ValueError:在率之后出现的索引处不支持格式字符','(0x2c)。 So inside (locationId, userId, discountId, rate, <- that right there is what is causing the issue for some reason. 因此,在内部(locationId,userId,discountId,rate,<-表示存在某种原因导致此问题)。

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. 使用python 2.5

It looks to me like you have a simple typo in your VALUES statement: i% should be %i . 在我看来,您在VALUES语句中有一个简单的错字: i%应该是%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. 否则,小鲍比表将接管您的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python —值错误:索引968处的格式字符&#39;,&#39;(0x2c)不支持 - Python — Value Error: unsupported format character ',' (0x2c) at index 968 ValueError:使用dict格式化时,格式字符\\&#39;“ \\&#39;(0x22)不支持 - ValueError: unsupported format character \'"\' (0x22) when formatting with dict ValueError:使用%字符串格式时不支持的格式字符&#39;}&#39; - ValueError: unsupported format character '}' when use % string formatting 使用%字符串格式时,值错误不受支持的格式字符““” - Value Error unsupported format character '"' when using % string formatting 使用字符串格式时不支持的格式字符 - Unsupported format character when using string formatting “ValueError: Unsupported format character &#39; ” &#39; (0x22) at...&quot; in Python / String - “ValueError: Unsupported format character ' ” ' (0x22) at…" in Python / String ValueError:不支持的格式字符&#39;C&#39;(0x43) - ValueError: unsupported format character 'C' (0x43) ValueError:索引3处不支持的格式字符&#39;&lt;&#39;(0x3c) - ValueError: unsupported format character '<' (0x3c) at index 3 ValueError: 不支持的格式字符 ']' (0x5d) - ValueError: unsupported format character ']' (0x5d) python关键字字符串格式与&#39;%&#39;混淆错误:不支持的格式字符&#39;p&#39; - python keyword string formatting with '%' confusing error : unsupported format character 'p'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM