From 137162fc5a2eb21134003031ac8ceedbe34b0039 Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Oct 29 2015 20:21:49 +0000 Subject: refactor: raise an exception if the HTTP request fails (ex: bad user/pass) --- diff --git a/SOURCES/centos_cert b/SOURCES/centos_cert index e896bbe..c414b9d 100644 --- a/SOURCES/centos_cert +++ b/SOURCES/centos_cert @@ -46,23 +46,26 @@ def download_cert(username, password, topurl=None, servercacert=None, uploadcace servercaurl = urlparse.urlunsplit(servercaspliturl) with open(os.path.expanduser(defaults.USER_CERT_FILE), 'w') as usercertfile: - r = requests.post(userurl, params=params, verify=False) - response = r.text + r = requests.post(userurl, params=params) + try: + r.raise_for_status() + except requests.exceptions.HTTPError as e: + print e.message + sys.exit(1) - if r.status_code <= 400: - usercertfile.write(response) - else: - print r.statuscode - print r.text - print os.path.expanduser(defaults.USER_CERT_FILE) + response = r.text + usercertfile.write(response) with open(os.path.expanduser(defaults.SERVER_CA_CERT_FILE), 'w') as servercacertfile: - r = requests.get(servercaurl, params=params, verify=False) - response = r.text + r = requests.get(servercaurl, params=params) + try: + r.raise_for_status() + except requests.exceptions.HTTPError as e: + print e.message + sys.exit(1) - if r.status_code <= 400: - servercacertfile.write(response) - print os.path.expanduser(defaults.SERVER_CA_CERT_FILE) + response = r.text + servercacertfile.write(response) # for now upload-ca.cert is the same as the server-ca cert. let's link them here if os.path.exists(os.path.expanduser(defaults.UPLOAD_CA_CERT_FILE)):