diff options
-rw-r--r-- | lorrycontroller/gitano.py | 18 | ||||
-rw-r--r-- | lorrycontroller/proxy.py | 10 |
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) |