首页 > 解决方案 > argparse“找不到命令”

问题描述

使用简单密码(最多 10 个字符) argpass 有效

parser = argparse.ArgumentParser()
parser.add_argument('-p', '-password',dest='pwd',help='The password for authentication.')
args = parser.parse_args()

user = 'monitoring@domain.com'
pwd = args.pwd

conn = imaplib.IMAP4_SSL("outlook.office365.com")
conn.login(user,pwd)

但是我得到了 13 个字符的复杂密码

[1] 26160
bash: xxxxxxxx: command not found

(其中 xxxxxxxx 是最后 8 个密码字符)

script.py -password somepassword

标签: pythonargparse

解决方案


你正在运行类似的东西

script.py -password foo&xxxxxxxx

你的外壳解析为

script.py -password foo & xxxxxxxx

这导致在script.py -password foo后台运行命令,然后尝试运行命令xxxxxxxx。引用密码。

script.py -password 'foo&xxxxxxxx'

推荐阅读