1. 程式人生 > >EncodeError: 'latin-1' codec can't encode characters in position 69-70: ordinal not in range(

EncodeError: 'latin-1' codec can't encode characters in position 69-70: ordinal not in range(

utf8 http error: swd area 名稱 data- encode col

UnicodeEncodeError: ‘latin-1‘ codec can‘t encode characters in position 69-70: ordinal not in range(256)解決辦法

使用python3.X向數據庫插入中文數據的時候,提示:

大概步驟是:

anjuke_area = (513, ‘平陰‘, ‘http://jinan.anjuke.com‘, ‘2017-03-29 13:17:03‘)

print(‘開始鏈接數據庫‘)
conn = pymysql.connect( host=‘XX.XX.XX.XX‘, port=3306, user=‘root‘, passwd=‘root123‘, db=‘數據庫名稱‘)
print(‘鏈接數據庫成功‘)
cur = conn.cursor()

cur.execute("INSERT INTO anjuke_area(id, name, link, time) VALUES (%s,%s,%s,%s)",anjuke_area)

然後提示:

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


實際解決問題的辦法是。。。。。:

conn = pymysql.connect( host=‘XX.XX.XX.XX‘, port=3306, user=‘root‘, passwd=‘root123‘, db=‘數據庫名稱‘, charset="utf8")


最後增加一個 : , charset="utf8" 就好了

EncodeError: 'latin-1' codec can't encode characters in position 69-70: ordinal not in range(