[issue25068] The proxy key's string should ignore case.

Chuang Cao report at bugs.python.org
Fri Sep 11 10:46:13 CEST 2015


New submission from Chuang Cao:

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 <type>_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():
+            type = string.lower(type)
             setattr(self, '%s_open' % type,
                     lambda r, proxy=url, type=type, meth=self.proxy_open: \
                     meth(r, proxy, type))


I think the second way is a good way.

----------
components: Library (Lib)
messages: 250454
nosy: Chuang Cao
priority: normal
severity: normal
status: open
title: The proxy key's string should ignore case.
type: resource usage
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25068>
_______________________________________


More information about the Python-bugs-list mailing list