diff -r 278dd7eb2f2b Python/pythonrun.c --- a/Python/pythonrun.c Fri Dec 13 14:33:01 2013 +0100 +++ b/Python/pythonrun.c Fri Dec 13 17:29:58 2013 +0100 @@ -1166,6 +1166,14 @@ initstdio(void) encoding = _Py_StandardStreamEncoding; errors = _Py_StandardStreamErrors; if (!encoding || !errors) { + if (!errors) { + /* If LC_CTYPE uses the POSIX locale (aka "C locale"), use + the surrogateescape error handler by default. */ + char *loc = setlocale(LC_CTYPE, NULL); + if (loc != NULL && strcmp(loc, "C") == 0) + errors = "surrogateescape"; + } + pythonioencoding = Py_GETENV("PYTHONIOENCODING"); if (pythonioencoding) { char *err;