1

it's a part of my script:

parser = ArgumentParser(description='extract state from bamboo build xml')
parser.add_argument('-f', '--file', help='log file', required=True)
parser.add_argument('-e', '--emails', help='emails list', required=True, nargs='+')
parser.add_argument('-p', '--phone-numbers', help='phone numbers list', required=True, nargs='+')
parser.add_argument('--sms-body', '--sms-body', help='sms text', required=True, nargs='+')
parser.add_argument('--email-body', '--email-body', help='email text', required=True, nargs='+')
args = parser.parse_args()

when I use this command to run this script, I have no problem:

python3.6 example.py --emails abc@gmail.com aaaa@gmail.com --phone-numbers somePhoneNumbers --email-body mail test --sms-body SMS test

its ok and I have no problem but when I run next command:

python3.6 script.py --phone-numbers somePhoneNumbers --emails aaa@gmail.com --sms-body http://site-aaaa.com:8080/project.all?pageHistory&Username=admin&Password=admin --email-body http://site-a.com:8080/project.all?pageHistory&Username=admin&Password=admin

the output is something like this:

[1] 15991
[2] 15992
[3] 15993
[4] 15994
-bash: --email-body: command not found
[2]   Done                    Username=admin
[3]-  Exit 127                Password=admin --email-body http://site-a.com:8080/project.all?pageHistory
[4]+  Done                    Username=admin

[root@server scripts]# usage: script.py [-h] [-f FILE] -e EMAILS [EMAILS ...] -p
                             PHONE_NUMBERS [PHONE_NUMBERS ...] --sms-body
                             SMS_BODY [SMS_BODY ...] --email-body EMAIL_BODY
                             [EMAIL_BODY ...]
script.py: error: the following arguments are required: --email-body/--email-body
  • 1
    My guess is that `bash` has broken up that long string, or otherwise mangled it. Or maybe the `--sms-body` argument before that. It may require some quoting. You could check the `sys.argv` before parsing to see what is being passed to the parser. – hpaulj May 05 '20 at 15:47
  • thank you for your comment @hpaulj, it's bash problem and I solved it by wrapping my links in single quotes, but it is not a good approach I guess. and one more thing I'm using argparser not sys.argv can it cause the problem? – mohammadhasan dabbaghy May 05 '20 at 20:49

0 Answers0