Fix issues with encoding with Python 2