query = "SELECT * FROM devices WHERE devices.`id` LIKE '%{}%'".format("f2333")
datas = cur.query(query)
报错:
query = query % tuple([db.literal(item) for item in args])
TypeError: not enough arguments for format string
传入query语句拼接出来为
SELECT * FROM devices WHERE devices.`mac` LIKE '%f8272e010882%'
此时还在python解释器中运行,这里的%加后面的字符会被python解析为占位符,如%f为float,所以报错缺少参数。
解决
使用转义,转义%要使用%转义。
query = "SELECT * FROM devices WHERE devices.`id` LIKE '%%{}%%'".format("f2333")
datas = cur.query(query)