# Buggy code
def get_smart_data():
    """
    Get SMART attribute data
    :return: list of multi leveled dictionaries
             each dict has a key "DeviceName" with the identification of the device in smartctl
             also has keys of the SMART attribute id, with value of another dict of the attributes
             [
                {
                    "DeviceName": "/dev/sda blahblah",
                    "1":
                    {
                        "flags": "..",
                        "raw": "..",
                        etc,
                    }
                    ...
                }
             ]
    """
    stats = []
    # get all devices
    devlist = DeviceList()

    for dev in devlist.devices:
        stats.append(
            {
                "DeviceName": "{} {}".format(dev.name, dev.model),
            }
        )
        for attribute in dev.attributes:
            if attribute is None:
                pass
            else:
                attribdict = convert_attribute_to_dict(attribute)

                # we will use the attribute number as the key
                num = attribdict.pop("num", None)
                try:
                    assert num is not None
                except Exception as e:
                    # we should never get here, but if we do, continue to next iteration and skip this attribute
                    continue

                stats[-1][num] = attribdict
    return stats


# Traceback (TypeError)
root@malachor:~# glances
Traceback (most recent call last):
File "/usr/local/bin/glances", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.8/dist-packages/glances/__init__.py", line 145, in main
start(config=config, args=args)
File "/usr/local/lib/python3.8/dist-packages/glances/__init__.py", line 110, in start
mode = GlancesMode(config=config, args=args)
File "/usr/local/lib/python3.8/dist-packages/glances/standalone.py", line 78, in __init__
self.stats.update()
File "/usr/local/lib/python3.8/dist-packages/glances/stats.py", line 234, in update
self._plugins[p].update()
File "/usr/local/lib/python3.8/dist-packages/glances/plugins/glances_plugin.py", line 993, in wrapper
ret = fct(self, *args, **kw)
File "/usr/local/lib/python3.8/dist-packages/glances/plugins/glances_plugin.py", line 1003, in wrapper
ret = fct(*args, **kw)
File "/usr/local/lib/python3.8/dist-packages/glances/plugins/glances_smart.py", line 155, in update
stats = get_smart_data()
File "/usr/local/lib/python3.8/dist-packages/glances/plugins/glances_smart.py", line 98, in get_smart_data
devlist = DeviceList()
File "/usr/local/lib/python3.8/dist-packages/pySMART/device_list.py", line 56, in __init__
self._initialize()
File "/usr/local/lib/python3.8/dist-packages/pySMART/device_list.py", line 95, in _initialize
cmd = Popen([SMARTCTL_PATH, '--scan-open'], stdout=PIPE, stderr=PIPE)
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1583, in _execute_child
and os.path.dirname(executable)
File "/usr/lib/python3.8/posixpath.py", line 152, in dirname
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

# Fixed code
def get_smart_data():
    """
    Get SMART attribute data
    :return: list of multi leveled dictionaries
             each dict has a key "DeviceName" with the identification of the device in smartctl
             also has keys of the SMART attribute id, with value of another dict of the attributes
             [
                {
                    "DeviceName": "/dev/sda blahblah",
                    "1":
                    {
                        "flags": "..",
                        "raw": "..",
                        etc,
                    }
                    ...
                }
             ]
    """
    stats = []
    # get all devices
    try:
        devlist = DeviceList()
    except TypeError as e:
        # Catch error  (see #1806)
        logger.debug("Smart plugin error - Can not grab device list ({})".format(e))
        global import_error_tag
        import_error_tag = True
        return stats

    for dev in devlist.devices:
        stats.append(
            {
                "DeviceName": "{} {}".format(dev.name, dev.model),
            }
        )
        for attribute in dev.attributes:
            if attribute is None:
                pass
            else:
                attribdict = convert_attribute_to_dict(attribute)

                # we will use the attribute number as the key
                num = attribdict.pop("num", None)
                try:
                    assert num is not None
                except Exception as e:
                    # we should never get here, but if we do, continue to next iteration and skip this attribute
                    logger.debug(
                        "Smart plugin error - Skip the attribute {} ({})".format(
                            attribute, e
                        )
                    )
                    continue

                stats[-1][num] = attribdict
    return stats