[New-bugs-announce] [issue46862] subprocess makes environment blocks with duplicate keys on Windows
benrg
report at bugs.python.org
Fri Feb 25 23:19:39 EST 2022
New submission from benrg <benrudiak at gmail.com>:
On Windows, if one writes
env = os.environ.copy()
env['http_proxy'] = 'whatever'
or either of the documented equivalents ({**os.environ, ...} or (os.environ | {...})), and passes the resulting environment to subprocess.run or subprocess.Popen, the spawned process may get an environment containing both `HTTP_PROXY` and `http_proxy`. Most Win32 software will see only the first one, which contains the unmodified value from os.environ.
Because os.environ forces all keys to upper case, it's possible to work around this by using only upper case keys in the update, but that behavior of os.environ is nonstandard (issue 46861), and subprocess shouldn't depend on it always being true, nor should end users have to.
Since dicts preserve order, the user's (presumable) intent is preserved in the env argument. I think subprocess should do something like
env = {k.upper(): (k, v) for k, v in env.items()}
env = dict(env.values())
to discard duplicate keys, keeping only the rightmost one.
----------
components: Library (Lib), Windows
messages: 414068
nosy: benrg, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: subprocess makes environment blocks with duplicate keys on Windows
type: behavior
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46862>
_______________________________________
More information about the New-bugs-announce
mailing list