Fix test_encode for python3.