今天使用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)
时间: 2024-12-28 01:30:25