Open liaodaiguo123 opened 2 years ago
+1
已解决。
在print方法前添加以下内容,更改解码格式
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')
比如我报错的位置是 print_rollback_sql 内部
def print_rollback_sql(self, filename): sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030') """print rollback sql from tmp_file""" with open(filename, "rb") as f_tmp: batch_size = 1000 i = 0 for line in reversed_lines(f_tmp): print(line.rstrip()) if i >= batch_size: i = 0 if self.back_interval: print('SELECT SLEEP(%s);' % self.back_interval) else: i += 1
Traceback (most recent call last): File "C:\Users\thinkpad\Desktop\demo\binlog2sql-master\binlog2sql-master\binlog2sql\binlog2sql.py", line 150, in <mo le> binlog2sql.process_binlog() File "C:\Users\thinkpad\Desktop\demo\binlog2sql-master\binlog2sql-master\binlog2sql\binlog2sql.py", line 111, in pro ss_binlog print(sql) UnicodeEncodeError: 'gbk' codec can't encode character '\u2666' in position 311: illegal multibyte sequence PS C:\Users\thinkpad\Desktop\demo\binlog2sql-master\binlog2sql-master>