smart_bytes is what Django uses in similar case: https://github.com/django/django/blob/11cd7388f77aa9d12ab6b57285c3801b237e241b/django/core/cache/utils.py#L14