# Buggy code
def simple_get(module, url):
    resp, info = fetch_url(module, url, method="GET")

    result = None
    try:
        content = resp.read()
    except AttributeError:
        if info["body"]:
            content = info["body"]

    if content:
        if info["content-type"].startswith("application/json"):
            try:
                result = module.from_json(content.decode("utf8"))
            except ValueError:
                module.fail_json(
                    msg="Failed to parse the ACME response: {0} {1}".format(
                        url, content
                    )
                )
        else:
            result = content

    if info["status"] >= 400:
        module.fail_json(
            msg="ACME request failed: CODE: {0} RESULT: {1}".format(
                info["status"], result
            )
        )
    return result


# Traceback (KeyError)
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py", line 812, in <module>
main()
File "/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py", line 802, in main
client = ACMEClient(module)
File "/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py", line 521, in __init__
self.account = ACMEAccount(module)
File "/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py", line 316, in __init__
self.directory = ACMEDirectory(module)
File "/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py", line 289, in __init__
self.directory = simple_get(self.module, self.directory_root)
File "/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py", line 191, in simple_get
if info['content-type'].startswith('application/json'):
KeyError: 'content-type'

fatal: [default]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py\", line 812, in <module>\n    main()\n  File \"/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py\", line 802, in main\n    client = ACMEClient(module)\n  File \"/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py\", line 521, in __init__\n    self.account = ACMEAccount(module)\n  File \"/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py\", line 316, in __init__\n    self.directory = ACMEDirectory(module)\n  File \"/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py\", line 289, in __init__\n    self.directory = simple_get(self.module, self.directory_root)\n  File \"/tmp/ansible_f44oyk38/ansible_module_letsencrypt.py\", line 191, in simple_get\n    if info['content-type'].startswith('application/json'):\nKeyError: 'content-type'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def simple_get(module, url):
    resp, info = fetch_url(module, url, method="GET")

    result = {}
    try:
        content = resp.read()
    except AttributeError:
        content = info.get("body")

    if content:
        if info["content-type"].startswith("application/json"):
            try:
                result = module.from_json(content.decode("utf8"))
            except ValueError:
                module.fail_json(
                    msg="Failed to parse the ACME response: {0} {1}".format(
                        url, content
                    )
                )
        else:
            result = content

    if info["status"] >= 400:
        module.fail_json(
            msg="ACME request failed: CODE: {0} RESULT: {1}".format(
                info["status"], result
            )
        )
    return result