Python备份脚本上的BrokenPipeError
我创建了一个备份脚本,用于自动备份数据库。代码执行良好。但是,在执行结束时,它显示了一个断管错误Python备份脚本上的BrokenPipeError,python,python-3.x,subprocess,gzip,Python,Python 3.x,Subprocess,Gzip,我创建了一个备份脚本,用于自动备份数据库。代码执行良好。但是,在执行结束时,它显示了一个断管错误 import gzip import subprocess with gzip.open('backup.gz', 'wb') as f: popen = subprocess.Popen(['pg_dump', '--no-owner', '--no-acl', '-U', 'postgres', '-d', 'esell_db', '-h', '127.0.0.1'], stdout=
import gzip
import subprocess
with gzip.open('backup.gz', 'wb') as f:
popen = subprocess.Popen(['pg_dump', '--no-owner', '--no-acl', '-U', 'postgres', '-d', 'esell_db', '-h', '127.0.0.1'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
popen.stdin.write("rootVidhyaDhan123#!\n")
for stdout_line in iter(popen.stdout.readline, ""):
f.write(stdout_line.encode('utf-8'))
popen.stdin.close()
popen.stdout.close()
popen.wait()
这个答案可能会有所帮助:@Aziz也尝试过这些。不起作用。这个答案可能会有帮助:@Aziz也试过了。不工作。