centos7.5升级openEuler20.03碰到UnicodeEncodeError问题

File “/usr/bin/x2openEuler-upgrade”, line 14, in

main()

File “sut/workflow/actor.py”, line 334, in actor.main

File “sut/workflow/actor.py”, line 166, in actor.run_backup

File “./sut/backup/init.py”, line 9, in process

File “sut/backup/actor.py”, line 446, in actor.for_backup_process

File “sut/backup/actor.py”, line 359, in actor.BackupFiles.do_files_backup

File “sut/backup/actor.py”, line 139, in actor.BackupFiles.get_all_backup_files

File “sut/backup/actor.py”, line 128, in actor.BackupFiles.get_other_files

File “sut/backup/actor.py”, line 130, in actor.BackupFiles.get_other_files

File “sut/backup/actor.py”, line 77, in actor.BackupFiles.write_backup_list_to_file

UnicodeEncodeError: ‘utf-8’ codec can’t encode character ‘\udcd7’ in position 40: surrogates not allowed

[ ERROR ] - [centos2openEuler]: x2openEuler-upgrade backup failed, please check

2

##THE END##

2 Likes

报错是因为备份目录中文件名有特殊字符,代码解析时报错。
在用问题环境上 执行 如下python代码:

1 Like

-- coding: utf-8 --

import os

def fun():
dir=[‘/var’, ‘/etc’, ‘/boot’, ‘/usr’]
with os.fdopen(os.open(“test.txt”, os.O_RDWR|os.O_CREAT|os.O_APPEND, 0x600), ‘a’) as file_fd:
for i in dir:
fun2(i, file_fd)

def fun2(dirname, file_fd):
if os.path.isfile(dirname):
file_fd.write(dirname + ‘\n’)
elif os.path.isdir(dirname):
file_fd.write(dirname + ‘\n’)
if not os.listdir(dirname):
return
for mian_dir,sub_dir,file_name_list in os.walk(dirname):
for file_name in file_name_list:
try:
file_fd.write(file_name + ‘\n’)
except Exception:
print(mian_dir)
return

fun()

x2openEuler_python39 test.py 执行,或者 python3 test.py 执行。

执行完 会输出 不能解析文件所在的目录,找到有问题文件 重新改名 或者 手动移动到其他 其他备份。

然后重新 升级。

2 Likes

好贴,赞一个!!!

赞!