[issue24307] pip error on windows whose current user name contains non-ascii characters

Karthikeyan Singaravelan report at bugs.python.org
Sun Sep 23 01:48:25 EDT 2018


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

Thanks for the patch. Would you like to make a GitHub PR. I think it's a problem with optparse in general while trying to have a default value with unicode character and %default in the help string. The same code is present in Python 3 but strings are unicode by default. An example code will be below : 

# -*- coding: utf-8 -*-

from optparse import OptionParser

parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
                  help="write to FILE. Default value %default", metavar="FILE", default="早上好")

(options, args) = parser.parse_args()

$ python3.6 ../backups/bpo24307.py --help
Usage: bpo24307.py [options]

Options:
  -h, --help            show this help message and exit
  -f FILE, --file=FILE  write to FILE. Default value 早上好

$ python2.7 ../backups/bpo24307.py --help
Traceback (most recent call last):
  File "../backups/bpo24307.py", line 9, in <module>
    (options, args) = parser.parse_args()
  File "/usr/local/Cellar/python at 2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1400, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "/usr/local/Cellar/python at 2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1440, in _process_args
    self._process_long_opt(rargs, values)
  File "/usr/local/Cellar/python at 2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1515, in _process_long_opt
    option.process(opt, value, values, self)
  File "/usr/local/Cellar/python at 2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 789, in process
    self.action, self.dest, opt, value, values, parser)
  File "/usr/local/Cellar/python at 2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 811, in take_action
    parser.print_help()
  File "/usr/local/Cellar/python at 2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1670, in print_help
    file.write(self.format_help().encode(encoding, "replace"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 148: ordinal not in range(128)


Thanks

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue24307>
_______________________________________


More information about the Python-bugs-list mailing list