Fix _write_request (data encoding/decoding for sending) to support Python 3