I have
headers = {'content-type': 'application/soap+xml'}
which works fine. however I want this to be able to be specified as an argument so in my args lets say I have
--wsheaders {'content-type':\s'application/soap+xml'}
This comes through fine as
{'content-type': 'application/soap+xml'}
... however when I do
headers = args.wsheaders
I get a ton of errors. So obviously headers cant be a string. But there must be a way to store this where it can be read back in a variable? Any ideas?
EDIT: I cant use the single quotes around the argument. I'm still learning this but it appears I can't use single or double quotes around an argument when passing the arguments from a file, like I CAN but it doesn't work to group the chars together, it instead becomes a literal part of the argument which isn't helpful since I lose everything before or after a space. see the attachment for what it looks like in the file.
--wsheaders '{'content-type': 'application/soap+xml'}'
error when using single quotes or double quotes
Sync03.py: error: unrecognized arguments: 'application/soap+xml'}'
Sync03.py: error: unrecognized arguments: 'application/soap+xml'}"
so instead I use
--wsheaders {'content-type':\s'application/soap+xml'}
but then the \s needs to be replaced after the arg is entered which I do, but then the variable is a string and I'm back to the origial problem.
type=json.loads
doesn't work in the argument definition when there's a \s since it's an unrecognized json. If there was a way to replace the \s with argparse it might work to do that first...but I dont think thats possible. With a space then with a \s
Sync03.py: error: argument --wsheaders: invalid loads value: "{'content-type':"
Sync03.py: error: argument --wsheaders: invalid loads value: "{'content-type':\\s'application/soap+xml'}"
EDIT
parser.add_argument('--wsheaders', type=lambda x: json.loads(x.replace('\s', '').replace('\'', '"')))
This worked as per bschlueter comment directly below.