TypeError:Python中的escape_string()参数1(不可能的<bad format =“” char =“”>)

时间:2018-07-17 10:09:13

标签: python

我想在MySQL查询中转义一个字符串,因为字符串给我造成了问题。我正在使用MySQLdb并转义使用MySQLdb.escape_string("'")的字符串,但这给出了错误。
谁能告诉我为什么我会收到此错误?还是应该正确地转义该字符串?

代码

import MySQLdb

def database():
    global db
    db = MySQLdb.connect(host="host", user="user", passwd="sss",db="database_name")

database()
cursor = db.cursor()
var = "some's name"
MySQLdb.escape_string("'")
query = "select * from node Where io = '{}' ".format(var)
cursor.execute(query)
value = cursor.fetchone()
cursor.close()

错误

Traceback (most recent call last):

File "C:/Desktop/practise.py", line 30, in <module>
  MySQLdb.escape_string("'")

TypeError: escape_string() argument 1 (impossible bad format char>)

0 个答案:

没有答案