Skip to content

Commit

Permalink
request-certificate: Handle JSON formatted responses
Browse files Browse the repository at this point in the history
We have moved over to using JSON formatted error messages, rather than
html templates.

This fixes issue #26
  • Loading branch information
Spindel committed Jun 17, 2015
1 parent 1c3d8b1 commit 03d6aa7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion request-certificate/caramelrequest/certificaterequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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//'))
Expand Down

0 comments on commit 03d6aa7

Please sign in to comment.