Fix encoding issues, Python 2 compatibility.

The removal of the assert is annoying, but otherwise it would have to be
conditional based on the Python version.