diff --git a/request-certificate/caramelrequest/certificaterequest.py b/request-certificate/caramelrequest/certificaterequest.py index e9c5beb..881f071 100755 --- a/request-certificate/caramelrequest/certificaterequest.py +++ b/request-certificate/caramelrequest/certificaterequest.py @@ -168,7 +168,7 @@ def request_cert_from_server(self): break else: logging.error('Request failed: {}' - .format(parse_html(response))) + .format(parse(response))) response.raise_for_status() break @@ -182,6 +182,14 @@ def printerr(text): sys.stderr.write(text + '\n') +def parse(response): + try: + result = response.json() + except Exception: + result = parse_html(response) + return result + + def parse_html(response): return ''.join((e.text or '') + (e.tail or '') for e in ET.fromstring(response.text).iterfind('body//'))