Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TypeError:Python中的escape_string()参数1(不可能<;格式错误char>;)_Python - Fatal编程技术网

TypeError:Python中的escape_string()参数1(不可能<;格式错误char>;)

TypeError:Python中的escape_string()参数1(不可能<;格式错误char>;),python,Python,我想在MySQL查询中转义字符串,因为字符串给我带来了问题。我正在使用MySQLdb,为了转义我正在使用的字符串,我使用了MySQLdb.escape_string(“”),但这给出了错误。 有人能告诉我为什么我会犯这个错误吗?或者该如何正确转义此字符串 代码 import MySQLdb def database(): global db db = MySQLdb.connect(host="host", user="user", passwd="sss",db="datab

我想在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>)
回溯(最近一次呼叫最后一次):
文件“C:/Desktop/practice.py”,第30行,在
MySQLdb.escape_字符串(“”)
TypeError:escape_string()参数1(不可能的错误格式char>)

看起来MySQLdb.escape_字符串(“”)需要一个字符。您是否厌倦了MySQLdb.escape\u string(')或MySQLdb.escape\u string(\')是的,这会给您带来语法错误也许这个问题可以帮助您解决此错误类型错误:escape\u string()正好接受1个参数(给定0)