# Buggy code
def on_header(hdr):
    if write_body[1] is not False and write_body[2] is None:
        # Try to find out what content type encoding is used if this is a text file
        write_body[1].parse_line(hdr)  # pylint: disable=no-member
        if "Content-Type" in write_body[1]:
            content_type = write_body[1].get("Content-Type")  # pylint: disable=no-member
            if not content_type.startswith("text"):
                write_body[1] = write_body[2] = False
            else:
                encoding = "utf-8"
                fields = content_type.split(";")
                for field in fields:
                    if "encoding" in field:
                        encoding = field.split("encoding=")[-1]
                write_body[2] = encoding
                # We have found our encoding. Stop processing headers.
                write_body[1] = False

    if write_body[0] is not None:
        # We already parsed the first line. No need to run the code below again
        return

    try:
        hdr = parse_response_start_line(hdr)
    except HTTPInputError:
        # Not the first line, do nothing
        return
    write_body[0] = hdr.code not in [301, 302, 303, 307]
    write_body[1] = HTTPHeaders()


# Traceback (AttributeError)
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/state.py", line 1822, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1727, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/states/pkg.py", line 1300, in installed
**kwargs)
File "/usr/lib/python2.7/site-packages/salt/states/pkg.py", line 541, in _find_install_targets
source_info = __salt__['lowpkg.bin_pkg_info'](cached_path)
File "/usr/lib/python2.7/site-packages/salt/modules/rpm.py", line 120, in bin_pkg_info
for field in pkginfo._fields:
AttributeError: 'NoneType' object has no attribute '_fields'

[WARNING ] The function "module.run" is using its deprecated version and will expire in version "Fluorine".

# Fixed code
def on_header(hdr):
    if write_body[1] is not False and write_body[2] is None:
        # Try to find out what content type encoding is used if
        # this is a text file
        write_body[1].parse_line(hdr)  # pylint: disable=no-member
        if "Content-Type" in write_body[1]:
            content_type = write_body[1].get("Content-Type")  # pylint: disable=no-member
            if not content_type.startswith("text"):
                write_body[1] = write_body[2] = False
            else:
                encoding = "utf-8"
                fields = content_type.split(";")
                for field in fields:
                    if "encoding" in field:
                        encoding = field.split("encoding=")[-1]
                write_body[2] = encoding
                # We have found our encoding. Stop processing headers.
                write_body[1] = False

            # If write_body[0] is False, this means that this
            # header is a 30x redirect, so we need to reset
            # write_body[0] to None so that we parse the HTTP
            # status code from the redirect target.
            if write_body[0] is write_body[1] is False:
                write_body[0] = None

    # Check the status line of the HTTP request
    if write_body[0] is None:
        try:
            hdr = parse_response_start_line(hdr)
        except HTTPInputError:
            # Not the first line, do nothing
            return
        write_body[0] = hdr.code not in [301, 302, 303, 307]
        write_body[1] = HTTPHeaders()