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: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1436203&group_id=5470
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: Hi, 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 unix_getpass passwd = _raw_input(prompt) File "/usr/lib/python2.4/getpass.py", line 74, in _raw_input 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')) Contraseña: I think you should be able to directly give a Unicode string to getpass(), as you can also give a Unicode string to print. Daniel ---------------------------------------------------------------------- Comment By: kxroberto (kxroberto) Date: 2006-04-24 12:39 Message: Logged In: YES user_id=972995 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: http://groups.google.de/group/comp.lang.python/msg/eac9b025b93e0642 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 (xy,'backslashreplace') * bin file's .encoding=('latin1','strict') * site(customize).py's defaultencoding should be/accept a tuple ('ascii','replace') -robert ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1436203&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com