[issue6501] Fatal error on startup with invalid PYTHONIOENCODING

Alexander Belopolsky report at bugs.python.org
Wed Feb 2 22:23:01 CET 2011


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

The issue is not Windows specific, so I am changing the title to reflect that.   On OSX, for example, I get

$ PYTHONIOENCODING=xyz ./python.exe
Fatal Python error: Py_Initialize: can't initialize sys standard streams
LookupError: unknown encoding: xyz
Abort trap

I agree that abort() is too drastic for a typo in the environment variable setting, but ignoring it silently is not a good option either.  Someone setting PYTHONIOENCODING most likely does it for a reason and giving him or her some sort of default behavior for mistyped encoding is not helpful.  (Note that this is how many C libraries treat TZ environment variable setting and this is often very frustrating.)

I think errors in environment variables that can be detected on startup should be treated the same way as the command line typos: a descriptive message on C stderr and exit(1).

Currently different environment variables are treated differently.  For example, mistakes in PYTHONHOME and PYTHONIOENCODING cause fatal error while an error in PYTHONSTARTUP is reported but does not terminate python:

$ PYTHONSTARTUP=xyz.py ./python.exe
Python 3.2rc2+ (py3k:88320, Feb  2 2011, 14:07:18) 
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Could not open PYTHONSTARTUP
IOError: [Errno 2] No such file or directory: 'xyz.py'
>>>

----------
nosy: +belopolsky
title: Fatal LookupError: unknown encoding: cp0 on Windows embedded startup. -> Fatal error on startup with invalid PYTHONIOENCODING

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6501>
_______________________________________


More information about the Python-bugs-list mailing list