With simple password (up to 10 characters) argpass works
parser = argparse.ArgumentParser()
parser.add_argument('-p', '-password',dest='pwd',help='The password for authentication.')
args = parser.parse_args()
user = '[email protected]'
pwd = args.pwd
conn = imaplib.IMAP4_SSL("outlook.office365.com")
conn.login(user,pwd)
But with complex password with 13 characters i'm getting
[1] 26160
bash: xxxxxxxx: command not found
(where xxxxxxxx are last 8 password characters)
script.py -password somepassword
asked Jan 3, 2019 at 14:51
user10205566
1 Answer 1
You are running something like
script.py -password foo&xxxxxxxx
which your shell parses as
script.py -password foo & xxxxxxxx
which results in running the command script.py -password foo in the background, then attempting to run the command xxxxxxxx. Quote the password.
script.py -password 'foo&xxxxxxxx'
answered Jan 3, 2019 at 14:54
chepner
538k77 gold badges596 silver badges747 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
chepner
There are other reasons why you might need to quote the password as a command-line argument; don't let shell syntax dictate what you can or can't use as a password. Use shell syntax to correctly use the password you choose.
lang-py
&in it, and you aren't properly quoting it when you run the command. This is a shell issue, not a Python issue.&, you can't remove it; you have to quote it.