Encode strings in basic python objects.

def encode_simple(d):
    """Encode strings in basic python objects."""
    if isinstance(d, unicode):
        return d.encode()
    if isinstance(d, list):
        return list(map(encode_simple, d))
    if isinstance(d, dict):
        return dict([(encode_simple(k), encode_simple(v)) for k, v in d.items()])
    return d