python/cpython · error · ValueError

Invalid address: must be None or {self._address}

Error message

Invalid address: must be None or {self._address}

What it means

Error "Invalid address: must be None or {self._address}" thrown in python/cpython.

Source

Thrown at Lib/asyncio/proactor_events.py:489

        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 off
            self._loop_writing()
        # else: A write operation is already kicked off

        self._maybe_pause_protocol()

View on GitHub (pinned to bc6749cc3b)

Solutions

  1. Pass None or the exact address the socket is connected to; use transport.get_extra_info('peername') to discover the valid address.

When it happens

Trigger: Raised when sendto() is given an address that is neither None nor the transport's bound address.

Common situations: See trigger scenarios.


AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14). Data as JSON: /api/errors/0cbe98355e28d4a8. Report an issue: GitHub.