UnicodeEncodeError: 'gbk' codec can't encode character '\ufeff' in position 0: illegal multibyte seq

执行下面脚本时报错:
line 76, in
cursor.execute(sql)
UnicodeEncodeError: ‘gbk’ codec can’t encode character ‘\ufeff’ in position 0: illegal multibyte sequence

with open(f_sql,'r',encoding='utf8') as f:
                sqls = f.read()
for sql in sqls.split(';'):
                sql = sql.strip()
                if not sql:
                    break

                cursor.execute(sql)
                

折腾许久,用ue将文件转码utf8格式,用记事本另存为utf8格式,还是报错,最后用notepad++打开查看文件编码是 UTF-8-BOM,转换为utf-8以后,执行成功

你可能感兴趣的:(UnicodeEncodeError: 'gbk' codec can't encode character '\ufeff' in position 0: illegal multibyte seq)