{"record":{"id":"831a2cccb5fdb143","repo":"RustPython/RustPython","slug":"python-ssl-module-is-not-available","errorCode":null,"errorMessage":"Python ssl module is not available","messagePattern":"Python ssl module is not available","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/base_events.py","lineNumber":1324,"sourceCode":"                await proto.drain()\n                total_sent += read\n        finally:\n            if total_sent > 0 and hasattr(file, 'seek'):\n                file.seek(offset + total_sent)\n            await proto.restore()\n\n    async def start_tls(self, transport, protocol, sslcontext, *,\n                        server_side=False,\n                        server_hostname=None,\n                        ssl_handshake_timeout=None,\n                        ssl_shutdown_timeout=None):\n        \"\"\"Upgrade transport to TLS.\n\n        Return a new transport that *protocol* should start using\n        immediately.\n        \"\"\"\n        if ssl is None:\n            raise RuntimeError('Python ssl module is not available')\n\n        if not isinstance(sslcontext, ssl.SSLContext):\n            raise TypeError(\n                f'sslcontext is expected to be an instance of ssl.SSLContext, '\n                f'got {sslcontext!r}')\n\n        if not getattr(transport, '_start_tls_compatible', False):\n            raise TypeError(\n                f'transport {transport!r} is not supported by start_tls()')\n\n        waiter = self.create_future()\n        ssl_protocol = sslproto.SSLProtocol(\n            self, protocol, sslcontext, waiter,\n            server_side, server_hostname,\n            ssl_handshake_timeout=ssl_handshake_timeout,\n            ssl_shutdown_timeout=ssl_shutdown_timeout,\n            call_connection_made=False)\n","sourceCodeStart":1306,"sourceCodeEnd":1342,"githubUrl":"https://github.com/RustPython/RustPython/blob/aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd/Lib/asyncio/base_events.py#L1306-L1342","documentation":"RuntimeError from BaseEventLoop.start_tls: asyncio's module-level `import ssl` failed, so ssl is None and no TLS upgrade is possible. This is an interpreter/build-level problem — the ssl module itself is missing or unimportable (not built with OpenSSL, restricted embedder, or an interpreter like RustPython where the native ssl module is unavailable).","triggerScenarios":"await loop.start_tls(transport, protocol, ctx) on an interpreter built without ssl support; embedders who did not register the ssl module; RustPython builds where _ssl is not compiled; broken OpenSSL installs making `import ssl` raise at interpreter startup.","commonSituations":"Embedded Python in a Rust/C application without TLS extensions; minimal or musl-based container images lacking OpenSSL; custom interpreter builds (RustPython, PyPy variants) without _ssl; CI matrices where one runner lacks the ssl build.","solutions":["Probe support before use: try: import ssl except ImportError: tls_enabled = False, and skip start_tls","On CPython, rebuild/reinstall Python with OpenSSL available (python -c 'import ssl' must succeed)","On embedded builds, register a native ssl module or route TLS through an external proxy/terminator"],"exampleFix":"# before\nnew_tr = await loop.start_tls(transport, protocol, ctx)\n\n# after\ntry:\n    import ssl  # noqa: F401\n    tls_ok = True\nexcept ImportError:\n    tls_ok = False\n\nif tls_ok:\n    new_tr = await loop.start_tls(transport, protocol, ctx)\nelse:\n    raise RuntimeError('TLS unavailable in this build; use a TLS terminator')","handlingStrategy":"validation","validationCode":"try:\n    import ssl\n    TLS_AVAILABLE = True\nexcept ImportError:\n    TLS_AVAILABLE = False\n\nif not TLS_AVAILABLE:\n    raise RuntimeError('ssl module unavailable; cannot start_tls')\nnew_tr = await loop.start_tls(transport, protocol, ctx)","typeGuard":"def tls_supported() -> bool:\n    try:\n        import ssl  # noqa: F401\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    new_tr = await loop.start_tls(transport, protocol, ctx)\nexcept RuntimeError as e:\n    if 'ssl module is not available' in str(e):\n        log.error('interpreter built without ssl; route TLS via terminator')\n    raise","preventionTips":["Run python -c 'import ssl' as an environment readiness check","Feature-detect TLS at startup and disable/short-circuit TLS code paths","On embedded interpreters, terminate TLS at a proxy when _ssl is absent"],"tags":["asyncio","ssl","tls","runtimeerror","build-config"],"backgroundTag":"ssl-module-unavailable","analyzedSha":"aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd","analyzedAt":"2026-08-17T00:37:52.100Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}