From 654d98c125ef7c17c2d406799d50461b066a2ccc Mon Sep 17 00:00:00 2001 From: Junaid Loonat Date: Mon, 25 Apr 2016 10:14:49 +0200 Subject: [PATCH] Use proxy for HTTPS requests as well Use proxy handler/opener classes, instead of request.set_proxy, to avoid any potential bugs in older Python versions. Use the HTTP proxy (if configured) for HTTPS requests as well. --- src/utils/web.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/web.py b/src/utils/web.py index 1d8e787f3..bc37eff9d 100644 --- a/src/utils/web.py +++ b/src/utils/web.py @@ -57,6 +57,7 @@ if minisix.PY2: return urllib.urlencode(*args, **kwargs).encode() from urllib2 import HTTPError, URLError from urllib import splithost, splituser + from urllib2 import build_opener, install_opener, ProxyHandler else: from http.client import InvalidURL from urllib.parse import urlsplit, urlunsplit, urlparse @@ -72,6 +73,7 @@ else: return urllib.parse.urlencode(*args, **kwargs) from urllib.error import HTTPError, URLError from urllib.parse import splithost, splituser + from urllib.request import build_opener, install_opener, ProxyHandler class Error(Exception): pass @@ -145,7 +147,12 @@ def getUrlFd(url, headers=None, data=None, timeout=None): request.add_data(data) httpProxy = force(proxy) if httpProxy: - request.set_proxy(httpProxy, 'http') + proxyHandler = ProxyHandler({ + 'http': httpProxy, + 'https': httpProxy + }) + proxyOpener = build_opener(proxyHandler) + install_opener(proxyOpener) fd = urlopen(request, timeout=timeout) return fd except socket.timeout as e: