jboutsicaris
jboutsicaris

Reputation: 23

Python argparse "unrecognized arguments" error

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

Upvotes: 2

Views: 8836

Answers (1)

Preston Martin
Preston Martin

Reputation: 2963

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

Upvotes: 3

Related Questions