-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The proxy key's string should ignore case. #69254
Comments
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.
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. |
This sounds like a feature enhancement, which means it (almost certainly) won't be applied to Python 2.7. Does the same question come up in Python 3? Also (FWIW) if you can confidently assume that all the keys are strings. then type.lower() is better than string.lower(type). |
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. |
On the other hand, a documentation update saying it has to be lower case would be fine for Python 2.7 and 3.4+, if you wanted to go that way. |
Thank you for your contribution, your PR has been merged into master but not in 3.8. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: