UnicodeDecodeError :“字符映射”编解码器无法解码位置的字节0x8d 7185:字符映射到
我不知道为什么会发生
import MySQLdb
import csv
import mysql.connector
cnx = mysql.connector.connect(user = 'root', password = '0000', host = '127.0.0.1', database = 'imdb' )
cursor = cnx.cursor()
def function():
'''
Write columns in stmt, and corresponsing amount of %s
'''
stmt = "INSERT INTO clips (Id,Title,Year,Type) VALUES (%s,%s,%s,%s)"
cursor.executemany(stmt, data)
cnx.commit()
cursor = cnx.cursor()
'''
filename
'''
clips = open('clips.csv', 'r')
data = []
count = 0
'''
remove [1:] if there is not a header in file
'''
for i in clips.readlines()[1:]:
count += 1
i = i.strip('\n').split(',')
for j, i_ in enumerate(i):
if i_ == '':
i[j] = None
data.append(tuple(i))
if count % 100000 == 0:
function()
print(count)
data = []
function()
cursor.close()
cnx.close()
我需要有关错误的帮助 预先感谢