Python 2.7 从unicode字符串中转义字符
我正在尝试将U0001f381字符串从ubuntu 14.04 LTS中的python 2.7.11存储到Azure sql server中。我已经将列类型设置为nvarchar(MAX),这样它就可以接受unicode字符串。 以下是python脚本:Python 2.7 从unicode字符串中转义字符,python-2.7,escaping,azure-sql-database,Python 2.7,Escaping,Azure Sql Database,我正在尝试将U0001f381字符串从ubuntu 14.04 LTS中的python 2.7.11存储到Azure sql server中。我已经将列类型设置为nvarchar(MAX),这样它就可以接受unicode字符串。 以下是python脚本: import pymssql from creds import * conn = pymssql.connect(host=HOST, user=USER, password=PASSWORD, database=DATABASE) curs
import pymssql
from creds import *
conn = pymssql.connect(host=HOST, user=USER, password=PASSWORD, database=DATABASE)
cursor = conn.cursor()
lst = [u'2017-07-04', u'\U0001f3e8', 1.0, 0.0, 0.0, 9.0]
print lst
placeholder = '%s,' * len(lst)
query = 'INSERT INTO Example_SearchAnalytics VALUES ( '+placeholder.rstrip(',')+ ')'
cursor.execute(query,tuple(lst))
conn.commit()
conn.close()
但当我在ubuntu环境中执行上面的脚本时,我遇到了以下错误
pymssql.OPERATIONALROR:(105,“在
字符串“”。数据库库错误消息20018,严重性15:\n一般
SQL Server错误:检查来自SQL Server的消息\n数据库错误
消息20018,严重性15:\n一般SQL Server错误:检查消息
从SQL Server中\n“
当我从windows环境执行相同的脚本时,我没有收到任何错误。我想我需要从unicode字符串中转义任何字符,但我不确定是哪个字符。
请提供帮助。重复引号或使用CHAR(39),如下文所述: 希望这有帮助 问候,
阿尔贝托·莫里洛(Alberto Morillo)我试着重复引号,但还是犯了同样的错误。我在插入表情符号时发现了这个案例,如