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.
Merge pull request #358 from brombomb/patch-1

Backwards compatibility for python < 3