Issue 25068: The proxy key's string should ignore case. (original) (raw)

When use a urllib2.ProxyHandler to set a proxy, if the proxies's key is an upper string, like "HTTP", "HTTPS". The proxy url can't be used, because they can't find the _open function.

Two way can sovle the issue.

  1. Specify it in document to let users to use a lower string like "http".

  2. Add a patch in urllib2.py:

diff -up ./urllib2.py.orig ./urllib2.py --- ./urllib2.py.orig 2015-09-11 15:06:55.686927934 +0800 +++ ./urllib2.py 2015-09-11 16:56:48.306138898 +0800 @@ -102,6 +102,7 @@ import sys import time import urlparse import bisect +import string

try: from cStringIO import StringIO @@ -713,6 +714,7 @@ class ProxyHandler(BaseHandler): assert hasattr(proxies, 'has_key'), "proxies must be a mapping" self.proxies = proxies for type, url in proxies.items():

I think the second way is a good way.

Looking at the code, I think Python 3 is in the same boat. Most things in Python are case-sensitive, but I think it is reasonable to make an exception here, since the protocol schemes in general are insensitive. E.g. urlopen("HTTPS://bugs.python.org/issue25068") still uses "https" internally.

It would be good to include a test case and a note in the documentation if we added this though.