sql where条件中含有中文,运行报错
#-*- coding: UTF-8 -*import cx_Oracle as cx
import json
import requests as re
import hashlib as hx
import sys
import importlib
importlib.reload(sys)
host="150.0.1.101"
port="1521"
sid="omrep"
conn=cx.connect("scott","tiger",cx.makedsn(host,port,sid))
cursor=conn.cursor()
sql="select * from v_pcore@test a where a.归属公司='南京驰宇发展有限公司'"
cursor.execute(sql)
rows=cursor.fetchall()
sha256 = hx.sha256()
sha256.update('d9ff90a9-a71f-460c-9e80-965e20c62282321'.encode('utf-8'))
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
res = sha256.hexdigest()
for row in rows :
data1 = {
"apikey": "87c8bc5c-e51c-426a-a91d-aff6753a58a9","salt": "321","signature": res,"userNames":
json.dumps([row[6]])
}
r1 = re.post("http://api-netadel., headers = headers,data=data1)
print(r1.text)
cursor.close
conn.close
很简单的一段代码 ,但是因为含有的sql语句中有中文,执行就会报错,去掉where条件就没有问题。
Traceback (most recent call last):
File "user.py", line 13, in <module>
cursor.execute(sql)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 37-40: ordinal not in range(128)