John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/147073

Change subject: Fix https proxy auth
......................................................................

Fix https proxy auth

urllib2 https proxy auth has not yet been fixed in
Proxy(Basic|Digest)AuthHandler.

http://bugs.python.org/issue7291

To workaround this bug, we must use ProxyHandler which has been fixed.

For the proxy support to be effective throughout the Pywikibot code,
MyURLopener must be set as the default opener with urllib2.install_opener.

Change-Id: Ib61587c9e3cfb920bdab117b139d1e3d06b8b3c7
---
M wikipedia.py
1 file changed, 15 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/compat 
refs/changes/73/147073/1

diff --git a/wikipedia.py b/wikipedia.py
index 2823641..76f96d3 100644
--- a/wikipedia.py
+++ b/wikipedia.py
@@ -10468,17 +10468,21 @@
 MyURLopener = urllib2.build_opener(U2RedirectHandler)
 
 if config.proxy['host']:
-    proxyHandler = urllib2.ProxyHandler({'http': 'http://%s/' % 
config.proxy['host'],
-                                         'https': 'https://%s' % 
config.proxy['host']})
+    if config.proxy['auth']:
+        proxy = {
+            'host': config.proxy['host'],
+            'user': urllib.quote(config.proxy['auth'][0], safe=''),
+            'pass': urllib.quote(config.proxy['auth'][1], safe='')
+        }
+        proxy = {'http': 'http://%(user)s:%(pass)s@%(host)s/' % proxy,
+                 'https': 'https://%(user)s:%(pass)s@%(host)s/' % proxy}
+    else:
+        proxy = {'http': 'http://%s/' % config.proxy['host'],
+                 'https': 'https://%s/' % config.proxy['host']}
+
+    proxyHandler = urllib2.ProxyHandler(proxy)
 
     MyURLopener.add_handler(proxyHandler)
-    if config.proxy['auth']:
-        proxyAuth = urllib2.HTTPPasswordMgrWithDefaultRealm()
-        proxyAuth.add_password(None, config.proxy['host'],
-                               config.proxy['auth'][0], 
config.proxy['auth'][1])
-        proxyAuthHandler = urllib2.ProxyBasicAuthHandler(proxyAuth)
-
-        MyURLopener.add_handler(proxyAuthHandler)
 
 if config.authenticate:
     passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
@@ -10491,6 +10495,8 @@
 
 MyURLopener.addheaders = [('User-agent', useragent)]
 
+urllib2.install_opener(MyURLopener)
+
 # The following will monkey-patch the pywikibot module to contain the same
 # functions and variables as wikipedia itself. This means we no longer have
 # to import wikipedia as pywikibot - instead, we can just import pywikibot

-- 
To view, visit https://gerrit.wikimedia.org/r/147073
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib61587c9e3cfb920bdab117b139d1e3d06b8b3c7
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to