我想在python中使用里尔酮。如果我不使用密码加密我的rclone,那么我可以这样做:
import subprocess
process = subprocess.Popen(["rclone", "listremotes"], shell=True, stdin=subprocess.PIPE)
output = process.communicate()
print(output)但是我想用密码来保护我的rclone,所以我需要一种将它发送给Rclone的方法。我跟踪了这个回答,但是我得到了错误Failed to read password: The handle is invalid
import subprocess
psw= input("enter psw")
psw_byte= str.encode(psw+'\n')
process = subprocess.Popen(["rclone", "listremotes"], shell=True, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.stdin.write(psw_byte)
process.stdin.flush()
output = process.communicate()
print(output)发布于 2018-04-25 19:54:51
我建议您使用RCLONE_CONFIG_PASS环境变量将配置密码传递给rclone。见文档中有关配置加密的部分。。
例如
os.environ("RCLONE_CONFIG_PASS") = "mypassword"除非您指定了tty,否则Unix程序读取密码往往不是这样的脚本。
这是一个相当大的麻烦,所以我建议只设置环境变量。
如果您只想为子进程设置环境,可以这样做:带有修改环境的Python子进程/Popen
PPS我是rclone的作者:-)
发布于 2020-08-22 01:27:41
这可能并不能准确地解决这个问题,但是,由于我还没有在其他地方找到这种形式,这里有一个在ipython和/或jupyter ipynb中使用的解决方案。
可以根据以下问题进行调整:
import getpass
rc_passwd = getpass.getpass()
! rclone --password-command "echo {rc_passwd}" lsd rc_remote:rc_path因为rc_path是rc_remote中的路径
发布于 2021-12-20 05:34:03
https://stackoverflow.com/questions/49588368
复制相似问题