Finally got 'to_bytes' to work in Python 2.7.