code: def safe_str(obj):
      
      try:
          return str(obj)
      except UnicodeEncodeError:
          # obj is unicode
          try:
              return unicode(obj).encode('unicode_escape')  # noqa for undefined-variable
          except NameError:
              # This is Python 3, just return the obj as it's already unicode
              return obj
docs: return the byte string representation of obj