New submission from benrg <benrud...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue46862>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to