python/cpython · error · Error

Not implemented

Error message

Not implemented

What it means

Raised by _ProactorBaseWritePipeTransport.sendto() (the proactor datagram transport, Windows IOCP) when the data argument is not a bytes-like object. Only bytes, bytearray, and memoryview are accepted; anything else (str, None, int, arbitrary objects) fails this isinstance check. The message text uses old %-style formatting, so it appears with a literal %r placeholder in some versions.

Source

Thrown at Platforms/emscripten/web_example_pyrepl_jspi/src.mjs:132

    return await Promise.race([p1, p2, p3]);
  } finally {
    h1.dispose();
    h2.dispose();
    h3.dispose();
  }
}

const FIONREAD = 0x541b;

const tty_stream_ops = {
  async readAsync(stream, buffer, offset, length, pos /* ignored */) {
    let readBytes = PTY.read(length);
    if (length && !readBytes.length) {
      const status = await waitForReadable(-1);
      if (status === waitResult.READY) {
        readBytes = PTY.read(length);
      } else {
        throw new Error("Not implemented");
      }
    }
    buffer.set(readBytes, offset);
    return readBytes.length;
  },

  write: (stream, buffer, offset, length) => {
    // Note: default `buffer` is for some reason `HEAP8` (signed), while we want unsigned `HEAPU8`.
    buffer = new Uint8Array(
      buffer.buffer,
      buffer.byteOffset,
      buffer.byteLength,
    );
    const toWrite = Array.from(buffer.subarray(offset, offset + length));
    PTY.write(toWrite);
    return length;
  },

View on GitHub (pinned to bc6749cc3b)

Solutions

  1. Encode string payloads before sending: data.encode('utf-8') for str, json.dumps(obj).encode() for objects
  2. Fix upstream functions that return None or non-bytes on error instead of sending their result
  3. Pass bytes(bytearray/memoryview) directly; convert numpy arrays with .tobytes() if needed
  4. Add a unit test asserting the payload type before send

Example fix

# before
transport.sendto(json.dumps({'cmd': 'ping'}))  # str -> TypeError
# after
transport.sendto(json.dumps({'cmd': 'ping'}).encode('utf-8'))
Defensive patterns

Strategy: type-guard

Validate before calling

def to_wire(data):
    if isinstance(data, str):
        return data.encode('utf-8')
    if isinstance(data, (bytes, bytearray, memoryview)):
        return data
    raise TypeError(f'cannot send {type(data).__name__} over datagram')

Type guard

def is_wire_bytes(d) -> bool:
    return isinstance(d, (bytes, bytearray, memoryview))

Try / catch

try:
    tr.sendto(payload)
except TypeError as e:
    if 'bytes-like' in str(e):
        raise TypeError(f'encode {type(payload).__name__} before send') from e
    raise

Prevention

When it happens

Trigger: Calling transport.sendto(data) or loop.sock_sendto-related datagram sends where data is a str (e.g. forgot .encode()), None from a failed serialization, a dict/list payload not json.dumps'd, or a generator. Also triggered when sendto is used on a connected TCP-style transport's API by mistake.

Common situations: Encoding mistakes: passing 'hello' instead of b'hello'; JSON over UDP where json.dumps(...) (str) is sent without .encode('utf-8'); a producer function returning None on an error path that gets sent anyway; pandas/numpy objects assumed to be buffers.

Related errors


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