[issue21169] getpass.getpass() fails with non-ASCII characters in prompt

Arfrever Frehtes Taifersar Arahesis report at bugs.python.org
Mon Apr 7 13:23:55 CEST 2014


New submission from Arfrever Frehtes Taifersar Arahesis:

getpass.getpass() fails with non-ASCII characters in prompt.

The attached example scripts (for Python 2 and 3) contain non-ASCII unicode prompt (Polish "hasło" == English "password") written in UTF-8.
Python-2 version fails always. Python-3 version fails in non-UTF-8 locale.

$ ./getpass_test_python2
Traceback (most recent call last):
  File "./getpass_test_python2", line 5, in <module>
    getpass.getpass(u"Hasło: ")
  File "/usr/lib64/python2.7/getpass.py", line 71, in unix_getpass
    passwd = _raw_input(prompt, stream, input=input)
  File "/usr/lib64/python2.7/getpass.py", line 128, in _raw_input
    prompt = str(prompt)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0142' in position 3: ordinal not in range(128)
$ LC_ALL="en_US.UTF-8" ./getpass_test_python3
Hasło: 
$ LC_ALL="C" ./getpass_test_python3
Traceback (most recent call last):
  File "./getpass_test_python3", line 5, in <module>
    getpass.getpass("Has\u0142o: ")
  File "/usr/lib64/python3.4/getpass.py", line 78, in unix_getpass
    passwd = _raw_input(prompt, stream, input=input)
  File "/usr/lib64/python3.4/getpass.py", line 138, in _raw_input
    stream.write(prompt)
UnicodeEncodeError: 'ascii' codec can't encode character '\u0142' in position 3: ordinal not in range(128)
$

----------
components: Library (Lib)
keywords: easy
messages: 215697
nosy: Arfrever
priority: normal
severity: normal
stage: needs patch
status: open
title: getpass.getpass() fails with non-ASCII characters in prompt
versions: Python 2.7, Python 3.4, Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21169>
_______________________________________


More information about the Python-bugs-list mailing list