diff -r e281a57d5b29 Doc/library/urllib.request.rst --- a/Doc/library/urllib.request.rst Tue Apr 19 08:53:14 2016 +0200 +++ b/Doc/library/urllib.request.rst Wed Apr 20 20:44:39 2016 +0200 @@ -166,6 +166,8 @@ in a case insensitive approach, for all operating systems first, and when it cannot find it, looks for proxy information from Mac OSX System Configuration for Mac OS X and Windows Systems Registry for Windows. + If both, lowercase and uppercase environment variables exist (and disagree), + lowercase is preferred. The following classes are provided: 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 Wed Apr 20 20:44:39 2016 +0200 @@ -2455,10 +2455,19 @@ """ proxies = {} + # in order to prefer lowercase variables, process environment in + # two passes: first matches any, second pass matches lowercase only for name, value in os.environ.items(): name = name.lower() if value and name[-6:] == '_proxy': proxies[name[:-6]] = value + for name, value in os.environ.items(): + if name[-6:] == '_proxy': + name = name.lower() + if value: + proxies[name[:-6]] = value + else: + proxies.pop(name[:-6], None) return proxies def proxy_bypass_environment(host): @@ -2467,6 +2476,7 @@ Checks the environment for a variable named no_proxy, which should be a list of DNS suffixes separated by commas, or '*' for all hosts. """ + # unlike no_proxy, the other vars are handled as mixed case variants also no_proxy = os.environ.get('no_proxy', '') or os.environ.get('NO_PROXY', '') # '*' is special case for always bypass if no_proxy == '*':