def fix_broken_encoding(value):
 if isinstance(value, six.text_type):
  value = value.encode('utf8', errors='replace')
 if isinstance(value, six.binary_type):
  value = value.decode('utf8', errors='replace')
 return value

def fix_broken_encoding ( value ) : if isinstance ( value , six . text_type ) : value = value . encode ( 'utf8' , errors = 'replace' ) if isinstance ( value , six . binary_type ) : value = value . decode ( 'utf8' , errors = 'replace' ) return value
strips broken characters that cant be represented at all in utf8 .