diff --git a/openstackclient/shell.py b/openstackclient/shell.py index b4f2df43b2..d6ce4ef661 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -18,7 +18,9 @@ import argparse import getpass +import locale import logging +import six import sys import traceback @@ -474,8 +476,17 @@ class OpenStackShell(app.App): tcmd.run(targs) -def main(argv=sys.argv[1:]): +def main(argv=None): + if argv is None: + argv = sys.argv[1:] + if six.PY2: + # Emulate Py3, decode argv into Unicode based on locale so that + # commands always see arguments as text instead of binary data + encoding = locale.getpreferredencoding() + if encoding: + argv = map(lambda arg: arg.decode(encoding), argv) + return OpenStackShell().run(argv) if __name__ == "__main__": - sys.exit(main(sys.argv[1:])) + sys.exit(main())