diff -r e281a57d5b29 Lib/urllib/request.py --- a/Lib/urllib/request.py Tue Apr 19 08:53:14 2016 +0200 +++ b/Lib/urllib/request.py Tue Apr 19 09:58:08 2016 +0200 @@ -2453,12 +2453,21 @@ different way, you can pass a proxies dictionary to the [Fancy]URLopener constructor. + If both lowercase and uppercase variables exist (and disagree), + lowercase overrules uppercase. """ proxies = {} + # in order to prioritize lowercase variables, + # process environment in two passes for name, value in os.environ.items(): - name = name.lower() - if value and name[-6:] == '_proxy': - proxies[name[:-6]] = value + if value and name[-6:] == '_PROXY': + proxies[name[:-6].lower()] = value + for name, value in os.environ.items(): + if name[-6:] == '_proxy': + if value: + proxies[name[:-6]] = value + else: + proxies.pop(name[:-6], None) return proxies def proxy_bypass_environment(host):