jenkins-bot has submitted this change and it was merged.

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.

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

Approvals:
  John Vandenberg: Looks good to me, but someone else must approve
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/wikipedia.py b/wikipedia.py
index 2823641..78de31d 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='')
+        }
+        credentials_and_host = '%(user)s:%(pass)s@%(host)s' % proxy
+    else:
+        credentials_and_host = config.proxy['host']
+
+    proxyHandler = urllib2.ProxyHandler(
+        {'http': 'http://%s/' % credentials_and_host,
+         'https': 'https://%s/' % credentials_and_host})
 
     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: merged
Gerrit-Change-Id: Ib61587c9e3cfb920bdab117b139d1e3d06b8b3c7
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
Pywikibot-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to