summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-02-11 10:13:35 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-02-11 10:13:35 +0000
commitce97e140f61cfc3781c3082febeacd0e5fb145cd (patch)
tree4288a083d607bfc60ed23e044aeb69539365dbe3
parent4b1fcab140d940470c342c6857cdc8682406f0b7 (diff)
parent18dec2bbe81b1d0d2bb5aca77034aecd42192779 (diff)
downloadlorry-controller-ce97e140f61cfc3781c3082febeacd0e5fb145cd.tar.gz
Merge branch 'sam/proxy-fixes'
Reviewed-By: Richard Maw <richard.maw@codethink.co.uk> Reviewed-By: Francisco Redondo Marchena <francisco.marchena@codethink.co.uk>
-rw-r--r--lorrycontroller/gitano.py18
-rw-r--r--lorrycontroller/proxy.py10
2 files changed, 7 insertions, 21 deletions
diff --git a/lorrycontroller/gitano.py b/lorrycontroller/gitano.py
index 3e36b81..6625757 100644
--- a/lorrycontroller/gitano.py
+++ b/lorrycontroller/gitano.py
@@ -21,6 +21,7 @@ import urllib2
import urlparse
import cliapp
+import requests
import lorrycontroller
@@ -113,21 +114,16 @@ class GitanoCommand(object):
logging.debug('url=%r', url)
try:
- request = urllib2.Request(url, None, {})
- logging.debug('request=%r', request.get_full_url())
if self.username and self.password:
- password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
- password_mgr.add_password(None, url, self.username, self.password)
- auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)
- opener = urllib2.build_opener(auth_handler)
- response = opener.open(url)
+ response = requests.get(url, auth=(self.username,
+ self.password))
else:
- response = urllib2.urlopen(request)
- except urllib2.URLError as e:
+ response = requests.get(url)
+ except (requests.exceptions.RequestException) as e:
raise GitanoCommandFailure(
self.trovehost, ' '.join(gitano_args), str(e))
-
- return response.read()
+
+ return response.text
class LocalTroveGitanoCommand(GitanoCommand):
diff --git a/lorrycontroller/proxy.py b/lorrycontroller/proxy.py
index 53d0667..22729d3 100644
--- a/lorrycontroller/proxy.py
+++ b/lorrycontroller/proxy.py
@@ -17,7 +17,6 @@
import json
import os
import urllib
-import urllib2
def build_proxy_url(protocol, proxy_config):
@@ -55,12 +54,3 @@ def setup_proxy(config_filename):
# set the required environment variables
os.environ['http_proxy'] = http_proxy_url
os.environ['https_proxy'] = https_proxy_url
-
- # create a ProxyHandler
- proxies = {'http_proxy': http_proxy_url,
- 'https_proxy': https_proxy_url}
- proxy_handler = urllib2.ProxyHandler(proxies)
-
- # install an opener to use the proxy
- opener = urllib2.build_opener(proxy_handler)
- urllib2.install_opener(opener)