Message250454
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. |
|
Date |
User |
Action |
Args |
2015-09-11 08:46:13 | Chuang Cao | set | recipients:
+ Chuang Cao |
2015-09-11 08:46:13 | Chuang Cao | set | messageid: <1441961173.2.0.654001525277.issue25068@psf.upfronthosting.co.za> |
2015-09-11 08:46:13 | Chuang Cao | link | issue25068 messages |
2015-09-11 08:46:12 | Chuang Cao | create | |
|