Change exception caught in ensure_encoded to UnicodeError.

This is probably the right generality.