diff -r 1f27572a10ce Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py Wed Aug 22 23:34:50 2012 -0700 +++ b/Lib/test/test_builtin.py Sun Aug 26 20:48:12 2012 +1000 @@ -1086,6 +1086,12 @@ sys.stdin = io.StringIO() self.assertRaises(EOFError, input) + sys.stdin = io.StringIO("the meaning of life") + sys.stdout = BitBucket() + sys.stdout.encoding = None + sys.stdout.errors = None + self.assertEqual(input('prompt'), "the meaning of life") + del sys.stdout self.assertRaises(RuntimeError, input, 'prompt') del sys.stdin diff -r 1f27572a10ce Python/bltinmodule.c --- a/Python/bltinmodule.c Wed Aug 22 23:34:50 2012 -0700 +++ b/Python/bltinmodule.c Sun Aug 26 20:48:12 2012 +1000 @@ -1709,8 +1709,19 @@ goto _readline_errors; stdout_encoding_str = _PyUnicode_AsString(stdout_encoding); stdout_errors_str = _PyUnicode_AsString(stdout_errors); - if (!stdout_encoding_str || !stdout_errors_str) - goto _readline_errors; + if (!stdout_encoding_str || !stdout_errors_str) { + /* invalid encoding or errors attributes on stdin, + check stderr for valid values */ + PyErr_Clear(); + stdout_encoding = _PyObject_GetAttrId(ferr, &PyId_encoding); + stdout_errors = _PyObject_GetAttrId(ferr, &PyId_errors); + if (!stdout_encoding || !stdout_errors) + goto _readline_errors; + stdout_encoding_str = _PyUnicode_AsString(stdout_encoding); + stdout_errors_str = _PyUnicode_AsString(stdout_errors); + if (!stdout_encoding_str || !stdout_errors_str) + goto _readline_errors; + } stringpo = PyObject_Str(promptarg); if (stringpo == NULL) goto _readline_errors;