# Buggy code
def _process_object_types(self, vobj, level=0):
    rdata = {}

    self.debugl("PROCESSING: %s" % str(vobj))

    if type(vobj) in self.safe_types:
        try:
            rdata = vobj
        except Exception as e:
            self.debugl(str(e))

    elif hasattr(vobj, "append"):
        rdata = []
        for vi in sorted(vobj):
            if type(vi) in self.safe_types:
                rdata.append(vi)
            else:
                if level + 1 <= self.maxlevel:
                    vid = self.facts_from_vobj(vi, level=(level + 1))
                    if vid:
                        rdata.append(vid)

    elif hasattr(vobj, "__dict__"):
        if level + 1 <= self.maxlevel:
            md = None
            md = self.facts_from_vobj(vobj, level=(level + 1))
            if md:
                rdata = md
    elif not vobj or type(vobj) in self.safe_types:
        rdata = vobj
    elif type(vobj) == datetime.datetime:
        rdata = str(vobj)
    else:
        self.debugl("unknown datatype: %s" % type(vobj))

    if not rdata:
        rdata = None
    return rdata


# Traceback (UnicodeEncodeError)
./vmware_inventory.py --list
Traceback (most recent call last):
File "./vmware_inventory.py", line 568, in <module>
print(VMWareInventory().show())
File "./vmware_inventory.py", line 109, in __init__
self.do_api_calls_update_cache()
File "./vmware_inventory.py", line 147, in do_api_calls_update_cache
instances = self.get_instances()
File "./vmware_inventory.py", line 282, in get_instances
instances = self._get_instances(kwargs)
File "./vmware_inventory.py", line 307, in _get_instances
ifacts = self.facts_from_vobj(instance)
File "./vmware_inventory.py", line 514, in facts_from_vobj
rdata[method] = self._process_object_types(methodToCall, level=level)
File "./vmware_inventory.py", line 545, in _process_object_types
md = self.facts_from_vobj(vobj, level=(level+1))
File "./vmware_inventory.py", line 487, in facts_from_vobj
rdata[k] = self._process_object_types(v, level=level)
File "./vmware_inventory.py", line 523, in _process_object_types
self.debugl("PROCESSING: %s" % str(vobj))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0159' in position 205: ordinal not in range(128)

# Fixed code
def _process_object_types(self, vobj, level=0):
    rdata = {}

    self.debugl("PROCESSING: %s" % vobj)

    if type(vobj) in self.safe_types:
        try:
            rdata = vobj
        except Exception as e:
            self.debugl(e)

    elif hasattr(vobj, "append"):
        rdata = []
        for vi in sorted(vobj):
            if type(vi) in self.safe_types:
                rdata.append(vi)
            else:
                if level + 1 <= self.maxlevel:
                    vid = self.facts_from_vobj(vi, level=(level + 1))
                    if vid:
                        rdata.append(vid)

    elif hasattr(vobj, "__dict__"):
        if level + 1 <= self.maxlevel:
            md = None
            md = self.facts_from_vobj(vobj, level=(level + 1))
            if md:
                rdata = md
    elif not vobj or type(vobj) in self.safe_types:
        rdata = vobj
    elif type(vobj) == datetime.datetime:
        rdata = str(vobj)
    else:
        self.debugl("unknown datatype: %s" % type(vobj))

    if not rdata:
        rdata = None
    return rdata