# Buggy code
def _parse_lsb_release_content(lines):
    """
    Parse the output of the lsb_release command.

    Parameters:

    * lines: Iterable through the lines of the lsb_release output.
             Each line must be a unicode string or a UTF-8 encoded byte
             string.

    Returns:
        A dictionary containing all information items.
    """
    props = {}
    for line in lines:
        line = line.decode("utf-8") if isinstance(line, bytes) else line
        kv = line.strip("\n").split(":", 1)
        if len(kv) != 2:
            # Ignore lines without colon.
            continue
        k, v = kv
        props.update({k.replace(" ", "_").lower(): v.strip()})
    return props


# Traceback (UnicodeDecodeError)
51_billappxz%pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
setuptools (38.2.4)
Traceback (most recent call last):
File "/data01/billappxz/scripts/ThirdParty/python27/bin/pip", line 11, in <module>
load_entry_point('pip==9.0.1', 'console_scripts', 'pip')()
File "/data01/billappxz/scripts/ThirdParty/python27/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/__init__.py", line 233, in main
return command.main(cmd_args)
File "/data01/billappxz/scripts/ThirdParty/python27/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 251, in main
timeout=min(5, options.timeout)) as session:
File "/data01/billappxz/scripts/ThirdParty/python27/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 72, in _build_session
insecure_hosts=options.trusted_hosts,
File "/data01/billappxz/scripts/ThirdParty/python27/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/download.py", line 329, in __init__
self.headers["User-Agent"] = user_agent()
File "/data01/billappxz/scripts/ThirdParty/python27/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/download.py", line 93, in user_agent
from pip._vendor import distro
File "/data01/billappxz/scripts/ThirdParty/python27/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/_vendor/distro.py", line 1050, in <module>
_distro = LinuxDistribution()
File "/data01/billappxz/scripts/ThirdParty/python27/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/_vendor/distro.py", line 594, in __init__
if include_lsb else {}
File "/data01/billappxz/scripts/ThirdParty/python27/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/_vendor/distro.py", line 922, in _get_lsb_release_info
stdout, stderr = stdout.decode('utf-8'), stderr.decode('utf-8')
File "/data01/billappxz/scripts/ThirdParty/python27/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd5 in position 24: invalid continuation byte

# Fixed code
def _parse_lsb_release_content(lines):
    """
    Parse the output of the lsb_release command.

    Parameters:

    * lines: Iterable through the lines of the lsb_release output.
             Each line must be a unicode string or a UTF-8 encoded byte
             string.

    Returns:
        A dictionary containing all information items.
    """
    props = {}
    for line in lines:
        kv = line.strip("\n").split(":", 1)
        if len(kv) != 2:
            # Ignore lines without colon.
            continue
        k, v = kv
        props.update({k.replace(" ", "_").lower(): v.strip()})
    return props