2

I am trying to use argparse to set up some simple command line options for a program I am writing. I do not understand why I am getting an error for "-u". I am using Python 2.7. Does anyone know what I am doing wrong?

Code: main.py -s 172.17.0.3 -p 8591 –u “user” -c “pass” -r 68.2

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-s", "--server", help="ip address of the server")
parser.add_argument("-p", "--port", help="port number of the server")
parser.add_argument("-u", "--user", help="username")
parser.add_argument("-c", "--pass", help="authentication credentials")
parser.add_argument("-r", "--record", help="port number of the server")
args = parser.parse_args()

Output: usage: main.py [-h] [-s SERVER] [-p PORT] [-u USER] [-c PASS] [-r RECORD] main.py: error: unrecognized arguments: �u �user�

Process finished with exit code 2

1 Answer 1

3

When you call main.py, check your argument that you are passing for the user (-u "user").

You are using an en dash (–) instead of a hyphen (-). These are different characters.

http://www.thepunctuationguide.com/en-dash.html

Sign up to request clarification or add additional context in comments.

1 Comment

Additionally, OP is using curly quotes around user instead of straight quotes.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.