有什么办法可以利用此代码:
course = course.replace('\'', '\\\'')
query = "SELECT * FROM student WHERE cost_per_unit > {}".format(course)
创建如下查询:
SELECT * FROM student WHERE cost_per_unit > 3; SELECT * FROM student WHERE column = 'ABC'
在这里,Python引发语法错误:
Syntax error at or near "\":
column = \'ABC\'
replace()
python中的方法替换了该方法。有什么变通办法,所以我可以注入某种东西吗?
解
由于我必须比较字符串,并且'
由于replace()
混乱而无法使用,因此我使用了$
美元报价
所以course
看起来像3; SELECT * FROM student WHERE column = $$ABC$$
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句