首页 > 代码库 > UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)

今天使用MySQLdb往MySQL插入中文数据遇到一个异常:

UnicodeEncodeError: ‘latin-1‘ codec can‘t encode characters in position 0-3: ordinal not in range(256)

解决办法:

conn = MySQLdb.connect(host="localhost", user="root", passwd="root", db="chemical", charset="utf8") 

 

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)