Python:如何在cursor.execute()中将unicode变量传递给sql server

时间:2017-11-30 09:48:57

标签: python unicode

在运行带代码

的python 2.7脚本时
with open(excelfile,'r') as openexcel:
    for line in openexcel:
        emp_firstname=line.split(',')[3]
        emp_lastname=line.split(',')[2]
        cursor.execute('SELECT id,Firstname,LastName FROM employee where 
        FirstName=? and LastName=?',emp_firstname,emp_lastname)

emp_firstname=line.split(',')[3]之后,emp_firstname值为Narélen,它会抛出错误,

cursor.execute('SELECT id,Firstname,LastName FROM employee where FirstName=? and LastName=?',emp_firstname,emp_lastname)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 3: ordinal not in range(128)

我也尝试了一些谷歌搜索,但仍然远离预期的结果。请建议一些方法来摆脱这个错误。

0 个答案:

没有答案