# Buggy code
def _parse_server_raw(server):
    """Parses a list of server directives.

    :param list server: list of directives in a server block
    :rtype: dict

    """
    parsed_server = {"addrs": set(), "ssl": False, "names": set()}

    apply_ssl_to_all_addrs = False

    for directive in server:
        if not directive:
            continue
        if directive[0] == "listen":
            addr = obj.Addr.fromstring(directive[1])
            parsed_server["addrs"].add(addr)
            if addr.ssl:
                parsed_server["ssl"] = True
        elif directive[0] == "server_name":
            parsed_server["names"].update(_get_servernames(directive[1]))
        elif directive[0] == "ssl" and directive[1] == "on":
            parsed_server["ssl"] = True
            apply_ssl_to_all_addrs = True

    if apply_ssl_to_all_addrs:
        for addr in parsed_server["addrs"]:
            addr.ssl = True

    return parsed_server


# Traceback (AttributeError)
Sending GET request to https://acme-staging.api.letsencrypt.org/directory.
Starting new HTTPS connection (1): acme-staging.api.letsencrypt.org
https://acme-staging.api.letsencrypt.org:443 "GET /directory HTTP/1.1" 200 372
Received response:
HTTP 200
Server: nginx
Content-Type: application/json
Content-Length: 372
Boulder-Request-Id: YEAeUNxir_MlrTWVJreyrS33D5Os8PVzytg-1B6vFi8
Replay-Nonce: pytUVIcXyJI1GtdD5Yek-PXthHeg5_XEHrww7zdtTnA
X-Frame-Options: DENY
Strict-Transport-Security: max-age=604800
Expires: Wed, 15 Feb 2017 16:05:39 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Wed, 15 Feb 2017 16:05:39 GMT
Connection: keep-alive

{
"key-change": "https://acme-staging.api.letsencrypt.org/acme/key-change",
"new-authz": "https://acme-staging.api.letsencrypt.org/acme/new-authz",
"new-cert": "https://acme-staging.api.letsencrypt.org/acme/new-cert",
"new-reg": "https://acme-staging.api.letsencrypt.org/acme/new-reg",
"revoke-cert": "https://acme-staging.api.letsencrypt.org/acme/revoke-cert"
}
Exiting abnormally:
Traceback (most recent call last):
File "/usr/local/bin/certbot", line 11, in <module>
sys.exit(main())
File "/opt/letsencrypt/local/lib/python2.7/site-packages/certbot/main.py", line 882, in main
return config.func(config, plugins)
File "/opt/letsencrypt/local/lib/python2.7/site-packages/certbot/main.py", line 658, in obtain_cert
domains, certname = _find_domains_or_certname(config, installer)
File "/opt/letsencrypt/local/lib/python2.7/site-packages/certbot/main.py", line 300, in _find_domains_or_certname
domains = display_ops.choose_names(installer)
File "/opt/letsencrypt/local/lib/python2.7/site-packages/certbot/display/ops.py", line 104, in choose_names
domains = list(installer.get_all_names())
File "/opt/letsencrypt/local/lib/python2.7/site-packages/certbot_nginx/configurator.py", line 389, in get_all_names
for vhost in self.parser.get_vhosts():
File "/opt/letsencrypt/local/lib/python2.7/site-packages/certbot_nginx/parser.py", line 141, in get_vhosts
parsed_server = _parse_server_raw(server)
File "/opt/letsencrypt/local/lib/python2.7/site-packages/certbot_nginx/parser.py", line 590, in _parse_server_raw
if addr.ssl:
AttributeError: 'NoneType' object has no attribute 'ssl'

An unexpected error occurred:
AttributeError: 'NoneType' object has no attribute 'ssl'
Please see the logfiles in /var/log/letsencrypt for more details.

# Fixed code
def _parse_server_raw(server):
    """Parses a list of server directives.

    :param list server: list of directives in a server block
    :rtype: dict

    """
    parsed_server = {"addrs": set(), "ssl": False, "names": set()}

    apply_ssl_to_all_addrs = False

    for directive in server:
        if not directive:
            continue
        if directive[0] == "listen":
            addr = obj.Addr.fromstring(directive[1])
            if addr:
                parsed_server["addrs"].add(addr)
                if addr.ssl:
                    parsed_server["ssl"] = True
        elif directive[0] == "server_name":
            parsed_server["names"].update(_get_servernames(directive[1]))
        elif directive[0] == "ssl" and directive[1] == "on":
            parsed_server["ssl"] = True
            apply_ssl_to_all_addrs = True

    if apply_ssl_to_all_addrs:
        for addr in parsed_server["addrs"]:
            addr.ssl = True

    return parsed_server