python/cpython · error · TypeError
data argument must be bytes-like object (%r)
Error message
data argument must be bytes-like object (%r)
What it means
Error "data argument must be bytes-like object (%r)" thrown in python/cpython.
Source
Thrown at Lib/asyncio/proactor_events.py:485
# constructor does it for us.
super().__init__(loop, sock, protocol, waiter=waiter, extra=extra)
# The base constructor sets _buffer = None, so we set it here
self._buffer = collections.deque()
self._loop.call_soon(self._loop_reading)
def _set_extra(self, sock):
_set_socket_extra(self, sock)
def get_write_buffer_size(self):
return self._buffer_size
def abort(self):
self._force_close(None)
def sendto(self, data, addr=None):
if not isinstance(data, (bytes, bytearray, memoryview)):
raise TypeError('data argument must be bytes-like object (%r)',
type(data))
if self._address is not None and addr not in (None, self._address):
raise ValueError(
f'Invalid address: must be None or {self._address}')
if self._conn_lost and self._address:
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
logger.warning('socket.sendto() raised exception.')
self._conn_lost += 1
return
# Ensure that what we buffer is immutable.
self._buffer.append((bytes(data), addr))
self._buffer_size += len(data) + self._header_size
if self._write_fut is None:
# No current write operations are active, kick one offView on GitHub (pinned to bc6749cc3b)
Solutions
- Pass bytes, bytearray, or memoryview to write()/sendto(); encode str with .encode() first.
When it happens
Trigger: Raised when a non-bytes-like object is passed to transport.write().
Common situations: See trigger scenarios.
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/d00c4b1e9220379b.
Report an issue: GitHub.