code: def force_encoding(value, encoding='utf-8'):
      
      if not isinstance(value, (str, unicode)):
          value = str(value)
      if isinstance(value, unicode):
          value = value.encode(encoding)
      elif encoding != 'utf-8':
          value = value.decode('utf-8').encode(encoding)
      return value
docs: Return a string encoded in the provided encoding