{"record":{"id":"0b086b5b9ec4edc9","repo":"python/cpython","slug":"sendfile-is-not-supported-for-transport-transport","errorCode":null,"errorMessage":"sendfile is not supported for transport {transport!r}","messagePattern":"sendfile is not supported for transport (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/base_events.py","lineNumber":1280,"sourceCode":"        count is the total number of bytes to transmit as opposed to\n        sending the file until EOF is reached. File position is updated on\n        return or also in case of error in which case file.tell()\n        can be used to figure out the number of bytes\n        which were sent.\n\n        fallback set to True makes asyncio to manually read and send\n        the file when the platform does not support the sendfile syscall\n        (e.g. Windows or SSL socket on Unix).\n\n        Raise SendfileNotAvailableError if the system does not support\n        sendfile syscall and fallback is False.\n        \"\"\"\n        if transport.is_closing():\n            raise RuntimeError(\"Transport is closing\")\n        mode = getattr(transport, '_sendfile_compatible',\n                       constants._SendfileMode.UNSUPPORTED)\n        if mode is constants._SendfileMode.UNSUPPORTED:\n            raise RuntimeError(\n                f\"sendfile is not supported for transport {transport!r}\")\n        if mode is constants._SendfileMode.TRY_NATIVE:\n            try:\n                return await self._sendfile_native(transport, file,\n                                                   offset, count)\n            except exceptions.SendfileNotAvailableError:\n                if not fallback:\n                    raise\n\n        if not fallback:\n            raise exceptions.SendfileNotAvailableError(\n                f\"fallback is disabled and native sendfile is not \"\n                f\"supported for transport {transport!r}\")\n        return await self._sendfile_fallback(transport, file,\n                                             offset, count)\n\n    async def _sendfile_native(self, transp, file, offset, count):\n        raise exceptions.SendfileNotAvailableError(","sourceCodeStart":1262,"sourceCodeEnd":1298,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/base_events.py#L1262-L1298","documentation":"A RuntimeError raised by loop.sendfile() when the transport does not support sendfile at all (its _sendfile_compatible attribute is UNSUPPORTED). Only specific transports (e.g. _SelectorSocketTransport on suitable platforms) advertise compatibility; SSL transports, pipes, subprocess pipes, and proxies report unsupported, and the message names the offending transport.","triggerScenarios":"Calling loop.sendfile(transport, ...) where transport is an SSL transport (start_tls result), a Read/WriteTransport over a pipe, or any custom/proxied transport lacking _sendfile_compatible. With fallback=False this RuntimeError path is distinct from SendfileNotAvailableError; UNSUPPORTED transports fail immediately.","commonSituations":"Serving files over HTTPS: the inner transport is SSL-wrapped and native sendfile cannot run; using asyncio.open_connection over TLS then calling sendfile; custom transports in frameworks.","solutions":["Use fallback=True so asyncio reads and send()s the file manually when native sendfile is impossible.","For HTTPS, don't rely on sendfile at all — stream chunks through transport.write().","Check getattr(transport, '_sendfile_compatible', None) before deciding to use sendfile."],"exampleFix":"// before\nawait loop.sendfile(ssl_transport, f, offset, count)  # RuntimeError\n\n// after\nawait loop.sendfile(ssl_transport, f, offset, count, fallback=True)","handlingStrategy":"fallback","validationCode":"from asyncio import constants\nmode = getattr(transport, '_sendfile_compatible', constants._SendfileMode.UNSUPPORTED)\nuse_sendfile = mode is not constants._SendfileMode.UNSUPPORTED","typeGuard":null,"tryCatchPattern":"try:\n    sent = await loop.sendfile(transport, f, offset, count, fallback=False)\nexcept (RuntimeError, Exception):\n    sent = await loop.sendfile(transport, f, offset, count, fallback=True)","preventionTips":["Pass fallback=True whenever the transport type is not guaranteed (SSL, pipes, proxies).","For HTTPS file serving, use chunked transport.write() loops instead of sendfile.","Check transport._sendfile_compatible before choosing the sendfile path."],"tags":["asyncio","sendfile","ssl","transport","unsupported-operation"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}