今天使用MySQLdb往MySQL插入中文數(shù)據(jù)遇到一個(gè)異常:UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)
解決辦法:
在創(chuàng)建連接的時(shí)候設(shè)置一下編碼,如:
conn = MySQLdb.connect(host="localhost", user="root", passwd="root", db="chemical",
charset="utf8")
posted on 2009-07-07 16:25
周銳 閱讀(3154)
評(píng)論(0) 編輯 收藏 所屬分類:
Python