Your change to unicode(term.value) will break with a UnicodeDecodeError if the value is a non-ASCII encoded string.
Your change to unicode(term.value) will break with a UnicodeDecodeError if the value is a non-ASCII encoded string.