[New-bugs-announce] [issue4006] os.getenv silently discards env variables with non-UTF-8 values

Toshio Kuratomi report at bugs.python.org
Wed Oct 1 09:17:21 CEST 2008

New submission from Toshio Kuratomi <a.badger at gmail.com>:

On a Linux system with a locale setting whose encoding is utf-8, if you
set an environment variable to have a non-utf-8 chanacter, that
environment variable silently does not appear in os.environ::

mkdir ñ
convmv -f utf-8 -t latin-1 --notest ñ
for i in * ; do export PATH=$PATH:$i ; done
echo $PATH
Python 3.0rc1 (r30rc1:66499, Sep 28 2008, 08:21:09) 
[GCC 4.3.0 20080428 (Red Hat 4.3.0-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['PATH']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.0/os.py", line 389, in __getitem__
    return self.data[self.keymap(key)]
KeyError: 'PATH'

I'm uncertain of the impact of this.  It was brought up in a discussion
of sending non-ASCii data to a CGI-WSGI script where the data would be
transferred via os.environ.

components: Unicode
messages: 74118
nosy: a.badger
severity: normal
status: open
title: os.getenv silently discards env variables with non-UTF-8 values
type: behavior

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list