Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.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
Python unicode excape下划线和双引号_Python_Mysql_Unicode_Python Unicode - Fatal编程技术网

Python unicode excape下划线和双引号

Python unicode excape下划线和双引号,python,mysql,unicode,python-unicode,Python,Mysql,Unicode,Python Unicode,我有代表不同语言用户名的数据。我已经执行了如下正确的Unicode流程: while attempts < 3 and not success: query = ur'''select gu_name from globaluser where gu_name = "{uname}"'''.format(uname=unicode(filerow['user_name'],'utf-8', errors='strict')) try: self.gdbCur

我有代表不同语言用户名的数据。我已经执行了如下正确的Unicode流程:

while attempts < 3 and not success:
    query = ur'''select gu_name from globaluser where gu_name = "{uname}"'''.format(uname=unicode(filerow['user_name'],'utf-8', errors='strict'))
    try:
        self.gdbCursor.execute(query.encode('utf-8'))
        gUser = self.gdbCursor.fetchone()
但我仍然得到以下错误:

ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'GG" Cooper"\' at line 1')

您应该按照以下建议使用参数输入:

以下是一个例子:

sql = "insert into foo values(%s)"
cursor.execute(sql, ('My very %$@*@"""S weird name',))

使用参数输入而不是字符串,你的名字将被数据库正确转义。你能给我一个很好的例子或链接吗?@Vor我用你提供的答案更新了我的代码,但没有真正起作用。我还更新了问题以显示我是如何做的。您是否尝试过在
%s
周围不使用
?是的,当我删除双引号时,我最终得到了一个操作错误。
操作错误:(1054,“where子句”中的未知列“Kelovy”)
sql = "insert into foo values(%s)"
cursor.execute(sql, ('My very %$@*@"""S weird name',))