diff -r ebe18b90618c Lib/getpass.py --- a/Lib/getpass.py Tue Apr 08 14:58:35 2014 -0400 +++ b/Lib/getpass.py Wed Apr 09 22:53:25 2014 +0530 @@ -19,6 +19,7 @@ import io import os import sys +import locale import warnings __all__ = ["getpass","getuser","GetPassWarning"] @@ -135,7 +136,13 @@ input = sys.stdin prompt = str(prompt) if prompt: - stream.write(prompt) + try: + stream.write(prompt) + except UnicodeEncodeError: + locale_encoding = locale.getpreferredencoding() + prompt = prompt.encode( locale_encoding, 'replace') + prompt = prompt.decode(locale_encoding) + stream.write(prompt) stream.flush() # NOTE: The Python C API calls flockfile() (and unlock) during readline. line = input.readline()