python/cpython · error · ValueError

only SOCK_STREAM type sockets are supported

Error message

only SOCK_STREAM type sockets are supported

What it means

Error "only SOCK_STREAM type sockets are supported" thrown in python/cpython.

Source

Thrown at Lib/asyncio/base_events.py:1001

                    blocksize = min(count - total_sent, blocksize)
                    if blocksize <= 0:
                        break
                view = memoryview(buf)[:blocksize]
                read = await self.run_in_executor(None, file.readinto, view)
                if not read:
                    break  # EOF
                await self.sock_sendall(sock, view[:read])
                total_sent += read
            return total_sent
        finally:
            if total_sent > 0 and hasattr(file, 'seek'):
                file.seek(offset + total_sent)

    def _check_sendfile_params(self, sock, file, offset, count):
        if 'b' not in getattr(file, 'mode', 'b'):
            raise ValueError("file should be opened in binary mode")
        if not sock.type == socket.SOCK_STREAM:
            raise ValueError("only SOCK_STREAM type sockets are supported")
        if count is not None:
            if not isinstance(count, int):
                raise TypeError(
                    "count must be a positive integer (got {!r})".format(count))
            if count <= 0:
                raise ValueError(
                    "count must be a positive integer (got {!r})".format(count))
        if not isinstance(offset, int):
            raise TypeError(
                "offset must be a non-negative integer (got {!r})".format(
                    offset))
        if offset < 0:
            raise ValueError(
                "offset must be a non-negative integer (got {!r})".format(
                    offset))

    async def _connect_sock(self, exceptions, addr_info, local_addr_infos=None):
        """Create, bind and connect one socket."""

View on GitHub (pinned to bc6749cc3b)

Solutions

  1. Use a SOCK_STREAM socket (TCP) for this API; datagram/UDP sockets require create_datagram_endpoint().

When it happens

Trigger: Raised when a non-SOCK_STREAM socket is used with pipe-based or stream-based loop APIs.

Common situations: See trigger scenarios.


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