[ python-Feature Requests-1436203 ] getpass.getpass() should allow Unicode prompts

SourceForge.net noreply at sourceforge.net
Mon Apr 24 12:39:57 CEST 2006

Feature Requests item #1436203, was opened at 2006-02-21 22:52
Message generated for change (Comment added) made by kxroberto
You can respond by visiting: 

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Unicode
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Daniel Herding (wikipedian)
Assigned to: Nobody/Anonymous (nobody)
Summary: getpass.getpass() should allow Unicode prompts

Initial Comment:

when using Python 2.4.1 on Linux, I get this:

>>> import getpass
>>> getpass.getpass(u'Contraseña: ')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/getpass.py", line 35, in
    passwd = _raw_input(prompt)
  File "/usr/lib/python2.4/getpass.py", line 74, in
    prompt = str(prompt)
UnicodeEncodeError: 'ascii' codec can't encode
character u'\xf1' in position 8: ordinal not in range(128)

This one works, but only if the user's console is using
UTF-8 encoding:

>>> getpass.getpass(u'Contraseña: '.encode('utf-8'))

I think you should be able to directly give a Unicode
string to getpass(), as you can also give a Unicode
string to print.



Comment By: kxroberto (kxroberto)
Date: 2006-04-24 12:39

Logged In: YES 

That error line in getpass should probably simply be
commented out?
Whats your sys.stdout.encoding ? (Probably not enough for
spanish chars as well)

The others will probably recommend to create sitecustomize.py

I'd say: Its a general trouble with Python that (console)
output encoding is in 'strict' mode by default. 
That crashes more apps, than it helps for discipline ...
And its hard even to grasp it and switch it for 'replace':
you'd need to replace sys.stdout with a custom formatter etc..

On MS Windows OS the MBCS conversion is kind of 'replace'
for good reason.  Even in Python on Win:
u"abc\u034adef".encode('mbcs') does replacing.

tty's,browser,windows,... and maybe most text mode files
(and even bin ones (latin1/replace?) ?) should not break.
The cases, where encoding should break strictly are
naturally cases where the programmer is aware (and puts the
conversion into strict mode expicitely)

"Python cannot print": Even a harmless 

>>> print u"abc\u034adef" 

throws an exception. That is questionable enough:


Maybe in future Python:
* encoding tuples should be accepted everywhere as
alternative to second argument: .encode((enc,error))
* text file's .encoding/.write_encoding=(xy,'replace') or
* bin file's .encoding=('latin1','strict')
* site(customize).py's defaultencoding should be/accept a
tuple ('ascii','replace')



You can respond by visiting: 

More information about the Python-bugs-list mailing list