0

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
3
  • Your password apparently has an & in it, and you aren't properly quoting it when you run the command. This is a shell issue, not a Python issue. Commented Jan 3, 2019 at 14:52
  • yes, it has &, i'll try removing it Commented Jan 3, 2019 at 14:53
  • If the password has a &, you can't remove it; you have to quote it. Commented Jan 3, 2019 at 14:54

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

just reset the password and removed & from it and it works now, thank you !!
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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.