我无法传递正确的密码,或者我在这个脚本中有误

I cannot pass correclty password or I am wrong in this script

我尝试将 borgfs 挂载到目录中。但是,此命令需要密码,因此,我必须将密码发送到标准输入。我在 Python 中找到了这个图书馆。但是,我无法挂载此 fs。我哪里错了?

./get.py 
<pexpect.pty_spawn.spawn object at 0x7f26997c5100>
command: /usr/bin/borgfs
args: ['/usr/bin/borgfs', '/home/sincorchetes/work/esmerald', '/mnt/work/esmerald']
buffer (last 100 chars): b' for key /home/sincorchetes/work/esmerald: '
before (last 100 chars): ''
after: b'Enter passphrase'
match: <re.Match object; span=(0, 16), match=b'Enter passphrase'>
match_index: 0
exitstatus: None
flag_eof: False
pid: 913893
child_fd: 5
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1

这是脚本的代码:

#!/mnt/aborg/bin/python
import pexpect

mypassword = "d6v6Q"
child = pexpect.spawn("borgfs /home/sincorchetes/work/esmerald /mnt/work/esmerald")
child.expect("Enter passphrase for key /home/sincorchetes/work/esmerald: ")
child.sendline(mypassword)

我认为基于输出,预期的 EOF 是这里的问题。您 期望登录时出现 EOF,您期望登录时提示密码。
例如

$ Enter passphrase for key /home/sincorchetes/work/esmerald: 
                                    You enter password here ^

您在同一行的冒号后输入密码,而不是像这样在下一行输入密码

$ Enter passphrase for key /home/sincorchetes/work/esmerald: 
$ 
  NOT here on the next line

将代码更改为

# rest of the code
child.expect('Enter passphrase for key /home/sincorchetes/work/esmerald: ')
# Remove this line child.expect(pexpect.EOF)
child.sendline(mypassword)

我可以看到 child.interact() 发生了什么。我在 borg 中有一个以前的缓存,我无法将此目录装入 push y word.

现在 100% 有效。

代码结果:

#!/mnt/aborg/bin/python
import pexpect

mypassword = "d6v6Q"
child = pexpect.spawn("borgfs /home/sincorchetes/work/esmerald /mnt/work/esmerald")
child.expect("Enter passphrase for key /home/sincorchetes/work/esmerald: ")
child.sendline(mypassword)
child.interact()

其余目录工作正常(不需要[y/N]回复。