Fix to_bytes for python3