def _convert_to_utf8(data_dict, binary=False):
    """
    Convert keys and values to unicode. If binary is flagged then only keys are
    converted.
    """
    item = {}
    for k, v in data_dict.items():
        k = str(k, 'utf8')
        if not binary:
            try:
                v = str(v, 'utf8', errors='ignore')
            except TypeError:
                v = str(v)
        item[k] = v
    return item
