def force_decode(string, encoding):
 if isinstance(string, bytes):
  try:
   if encoding:
    string = string.decode(encoding)
   else:
    string = string.decode('utf-8')
  except UnicodeError:
   string = string.decode('latin1')
 return string

def force_decode ( string , encoding ) : if isinstance ( string , bytes ) : try : if encoding : string = string . decode ( encoding ) else : string = string . decode ( 'utf-8' ) except UnicodeError : string = string . decode ( 'latin1' ) return string
forcibly get a unicode string out of a bytestring .