Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
liaodaiguo123 opened this issue Sep 30, 2022 · 2 comments
Open

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

liaodaiguo123 opened this issue Sep 30, 2022 · 2 comments

Comments

@liaodaiguo123
Copy link

liaodaiguo123 commented Sep 30, 2022

Traceback (most recent call last):
File "C:\Users\thinkpad\Desktop\demo\binlog2sql-master\binlog2sql-master\binlog2sql\binlog2sql.py", line 150, in
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
Copy link

+1

@xuezhenqiang000
Copy link

xuezhenqiang000 commented Jul 10, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants