0
我試圖做一個腳本來顯示我的數據庫,是8列,都與utf8_unicode_ci求婚。Python中的UnicodeEncodeError與.pychall()的pymysql()
這是腳本:
import sys
import pymysql
conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='root', db='rfid')
cur = conn.cursor()
cur.execute("SELECT * FROM cnf1")
for r in cur.fetchall():
print(r)
cur.close()
conn.close()
但運行腳本時,控制檯拋出我下面的錯誤:
(1, 'camilo', 'camilo', 'camilo', 'camilo', 'camilo', 'camilo', 'camilo')
(2, 'Juan', 'Perez', 'Sanchez', '112223330', 'Las Almendras 111', '[email protected]', '12AAA')
(3, 'a', 'a', 'a', 'a', 'a', 'a', 'a')
(4, 'camilo1', 'camilo1', 'camilo1', 'camilo1', 'camilo1', 'camilo1', 'camilo1')
Traceback (most recent call last):
File "/Users/camilonunezfernandez/Desktop/prueba2.py", line 11, in <module>
(5, 'camilo1', 'camilo1', 'camilo1', 'camilo1', 'camilo1', 'camilo1', 'camilo1')
(6, 'camilo1', 'camilo1', 'camilo1', 'camilo1', 'camilo1', 'camilo1', 'camilo1')
print(r)
UnicodeEncodeError: 'ascii' codec can't encode character '\xf1' in position 5: ordinal not in range(128)
[Finished in 0.4s with exit code 1]
[cmd: ['python3', '-u', '/Users/camilonunezfernandez/Desktop/prueba2.py']]
[dir: /Users/camilonunezfernandez/Desktop]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
我正在使用Python版本3.4,它運行「 pymysql'庫連接到我的MySQL數據庫。
他們知道這個錯誤可能會發生? 非常感謝!