Python unicode excape下划线和双引号

2024-05-13 20:37:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有代表不同语言用户名的数据。我执行了如下适当的unicoding过程:

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()

但当谈到这样的名字时,Name1_"GG"_Name1AnotherName我最后得到了以下错误:

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"\'在第1行')

如何正确编码这些类型的字符?在

更新:

根据提供的答案,我做了以下工作:

\'GG" Cooper"\'解析用户名

^{pr2}$

但我仍然得到以下错误:

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')

Tags: thetonameselfyour错误query用户名