danfengcao / binlog2sql

Parse MySQL binlog to SQL you want
GNU General Public License v3.0
3.33k stars 1.04k forks source link

win10下有编码问题。大神有没有有办法解决 #105

Open liaodaiguo123 opened 2 years ago

liaodaiguo123 commented 2 years ago

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>

xuezhenqiang000 commented 1 year ago

+1

xuezhenqiang000 commented 1 year ago

已解决。 在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