a bytes-like object is required, not 'str' 求助!
# 定义配置文件修改函数def config_modify(filename, old_str, new_str):
with open(filename, "rb") as f1, open("%s.bak" % filename, "wb") as f2:
n = 0
for line in f1:
if old_str in line:
n += 1
if n == 1:
print(line)
f2.write(re.sub(line, new_str, line))
else:
f2.write(line)
else:
f2.write(line)
os.remove(filename)
os.rename("%s.bak" % filename, filename)
minion_config = 'c:\\salt\\conf\\minion'
try:
config_modify(minion_config, 'id:', 'id:' + ' ' + 'test-server-01' + '\n')
config_modify(minion_config, 'master:', 'master:' + ' ' + 'salt-server' + '\n')
except Exception as e:
print(e)
报错信息:
a bytes-like object is required, not 'str' 求助,知道类型不对,不知道修改哪里... 发完整报错,别人也好帮你解决
页:
[1]