Backwards compatibility for python < 3

Python 2.6 doesn't support keyword arguments for str.encode.  Positional arguments work for both Python 2 and 3.