UnicodeEncodeError:'ascii'编解码器无法在位置3编码字符'\ xf6':序数不在范围内(128)

时间:2019-05-13 04:27:35

标签: python-3.7

我正在尝试将数据帧导出到oracle db。 我收到UNICODEENCODE错误

cursor2.prepare("INSERT INTO Employee_SM 
(EMPLOYEE,SUPERVISOR,EMP_NUM,EMP_NAME,SUP_NUM,SUP_NAME) VALUES (:1, :2, :3, :4, 
:5, :6)")
cursor2.executemany(None, rows)

1 个答案:

答案 0 :(得分:0)

由于查询数据库使用的字符串而导致unicode错误 请尝试以下编码/解码方法

>>> string = "this is unicode string §"
>>> type(string)
<class 'str'>
>>> inbytes = string.encode("utf-8")
>>> type(inbytes)
<class 'bytes'>
>>> inbytes
b'this is unicode string \xc2\xa7'
>>> againstr = inbytes.decode("utf-8")
>>> type(againstr)
<class 'str'>
>>> againstr
'this is unicode string §'
>>>