{"record":{"id":"84aa1fa270742847","repo":"redis/redis-py","slug":"python-wasn-t-built-with-ssl-support","errorCode":null,"errorMessage":"Python wasn't built with SSL support","messagePattern":"Python wasn't built with SSL support","errorType":"exception","errorClass":"RedisError","httpStatus":null,"severity":"critical","filePath":"redis/asyncio/connection.py","lineNumber":1535,"sourceCode":"\n    def __init__(\n        self,\n        ssl_keyfile: Optional[str] = None,\n        ssl_certfile: Optional[str] = None,\n        ssl_cert_reqs: Union[str, ssl.VerifyMode] = \"required\",\n        ssl_include_verify_flags: Optional[List[\"ssl.VerifyFlags\"]] = None,\n        ssl_exclude_verify_flags: Optional[List[\"ssl.VerifyFlags\"]] = None,\n        ssl_ca_certs: Optional[str] = None,\n        ssl_ca_data: Optional[str] = None,\n        ssl_ca_path: Optional[str] = None,\n        ssl_check_hostname: bool = True,\n        ssl_min_version: Optional[TLSVersion] = None,\n        ssl_ciphers: Optional[str] = None,\n        ssl_password: Optional[str] = None,\n        **kwargs,\n    ):\n        if not SSL_AVAILABLE:\n            raise RedisError(\"Python wasn't built with SSL support\")\n\n        self.ssl_context: RedisSSLContext = RedisSSLContext(\n            keyfile=ssl_keyfile,\n            certfile=ssl_certfile,\n            cert_reqs=ssl_cert_reqs,\n            include_verify_flags=ssl_include_verify_flags,\n            exclude_verify_flags=ssl_exclude_verify_flags,\n            ca_certs=ssl_ca_certs,\n            ca_data=ssl_ca_data,\n            ca_path=ssl_ca_path,\n            check_hostname=ssl_check_hostname,\n            min_version=ssl_min_version,\n            ciphers=ssl_ciphers,\n            password=ssl_password,\n        )\n        super().__init__(**kwargs)\n\n    def _connection_arguments(self) -> Mapping:","sourceCodeStart":1517,"sourceCodeEnd":1553,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/connection.py#L1517-L1553","documentation":"Raised as RedisError at the very top of SSLConnection.__init__ when the module-level SSL_AVAILABLE flag is False, i.e. this Python interpreter was compiled without the ssl module. The constructor fails before any socket is opened, so no async work has happened. This is an environment/build defect, not a runtime network issue.","triggerScenarios":"Instantiating redis.asyncio.Redis.from_url('rediss://...') or SSLConnection(...) (or any path that selects connection_class=SSLConnection) on a Python built without OpenSSL linkage (some minimal Docker images, custom-compiled pyenv builds, or Alpine without openssl-dev at build time).","commonSituations":"Custom/SLIM Python base image missing libssl; python built with --disable-ssl or a broken OpenSSL detect; python3-minimal packages; conda/pyenv builds on systems lacking openssl-dev headers at compile time.","solutions":["Use a CPython distribution built with OpenSSL (official python:3.x images, or rebuild with libssl-dev/openssl-devel installed).","In a container, switch from a minimal base to python:3.x-slim or python:3.x which bundle SSL.","If you cannot rebuild, use a non-SSL redis:// connection (only acceptable if transport is otherwise secured).","Verify with: python -c 'import ssl; print(ssl.OPENSSL_VERSION)'."],"exampleFix":"// before (custom python built without ssl)\nr = redis.asyncio.from_url('rediss://host:6379')\n// after\n# use python:3.12-slim base image, then:\nr = redis.asyncio.from_url('rediss://host:6379')","handlingStrategy":"validation","validationCode":"import ssl\n\ndef assert_ssl_available() -> None:\n    if not ssl.HAS_SSL:\n        raise RuntimeError('Python interpreter has no SSL support; use a build with OpenSSL')","typeGuard":"from redis.exceptions import RedisError\n\ndef is_no_ssl(exc: BaseException) -> bool:\n    return isinstance(exc, RedisError) and 'SSL support' in str(exc)","tryCatchPattern":"from redis.exceptions import RedisError\n\ntry:\n    r = redis.asyncio.from_url('rediss://host')\nexcept RedisError as e:\n    if 'SSL support' in str(e):\n        raise RuntimeError('Rebuild Python with OpenSSL or use redis:// (non-TLS)') from e\n    raise","preventionTips":["Base images on python:3.x-slim (which bundle OpenSSL).","Run python -c 'import ssl' as a startup sanity check.","Do not strip libssl from production images."],"tags":["ssl","build","environment","async","ssl-connection","config"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}