Running Python 2.7
When executing:
$ python client.py get_emails -a \"åäö\"
I get:
usage: client.py get_emails [-h] [-a
The command-line arguments are encoded using sys.getfilesystemencoding()
:
import sys
def commandline_arg(bytestring):
unicode_string = bytestring.decode(sys.getfilesystemencoding())
return unicode_string
# ...
parser_get_emails.add_argument('-a', '--area', type=commandline_arg)
Note: You don't need it in Python 3 (the arguments are already Unicode). It uses os.fsdecode() in this case because sometimes command-line arguments might be undecodable. See PEP 383 -- Non-decodable Bytes in System Character Interfaces.
You can try
type=lambda s: unicode(s, 'utf8')
instead of
type=unicode
Without encoding argument unicode() defaults to ascii.