{"id":"6a8eac6e56680a65","repo":"urllib3/urllib3","slug":"cryptography-module-missing-required-functionali","errorCode":null,"errorMessage":"'cryptography' module missing required functionality.  Try upgrading to v1.3.4 or newer.","messagePattern":"'cryptography' module missing required functionality\\.  Try upgrading to v1\\.3\\.4 or newer\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"src/urllib3/contrib/pyopenssl.py","lineNumber":170,"sourceCode":"def extract_from_urllib3() -> None:\n    \"Undo monkey-patching by :func:`inject_into_urllib3`.\"\n\n    util.SSLContext = orig_util_SSLContext\n    util.ssl_.SSLContext = orig_util_SSLContext\n    util.IS_PYOPENSSL = False\n    util.ssl_.IS_PYOPENSSL = False\n\n\ndef _validate_dependencies_met() -> None:\n    \"\"\"\n    Verifies that PyOpenSSL's package-level dependencies have been met.\n    Throws `ImportError` if they are not met.\n    \"\"\"\n    # Method added in `cryptography==1.1`; not available in older versions\n    from cryptography.x509.extensions import Extensions\n\n    if getattr(Extensions, \"get_extension_for_class\", None) is None:\n        raise ImportError(\n            \"'cryptography' module missing required functionality.  \"\n            \"Try upgrading to v1.3.4 or newer.\"\n        )\n\n    # pyOpenSSL 0.14 and above use cryptography for OpenSSL bindings. The _x509\n    # attribute is only present on those versions.\n    from OpenSSL.crypto import X509\n\n    x509 = X509()\n    if getattr(x509, \"_x509\", None) is None:\n        raise ImportError(\n            \"'pyOpenSSL' module missing required functionality. \"\n            \"Try upgrading to v0.14 or newer.\"\n        )\n\n\ndef _dnsname_to_stdlib(name: str) -> str | None:\n    \"\"\"","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/urllib3/urllib3/blob/c8d039c1b743f0bf5ee136972c68350fd91d41f1/src/urllib3/contrib/pyopenssl.py#L152-L188","documentation":"Raised by pyopenssl._validate_dependencies_met() when the installed 'cryptography' package predates v1.3.4 and lacks Extensions.get_extension_for_class. urllib3's pyOpenSSL contrib shim relies on that method, so it refuses to monkey-patch itself in and instructs the user to upgrade cryptography. It fires at injection time (when the contrib module is wired into urllib3).","triggerScenarios":"Importing urllib3.contrib.pyopenssl (or code that injects it) in an environment with cryptography < 1.3.4; a legacy pinned stack where cryptography is intentionally old; a fresh env that pulled an ancient transitive cryptography version.","commonSituations":"Long-running legacy projects with frozen dependency pins; systems where the OS package provides an old python-cryptography; upgrading pyOpenSSL without also upgrading cryptography.","solutions":["Upgrade the cryptography package: `pip install -U cryptography` (target >= 1.3.4, but in practice use a current release).","Refresh all TLS-related pins together (cryptography + pyOpenSSL).","If you don't actually need the pyOpenSSL shim, stop importing urllib3.contrib.pyopenssl and use urllib3's native ssl backend."],"exampleFix":"// before\n$ pip install cryptography==1.2  # too old\n\n// after\n$ pip install -U cryptography pyOpenSSL","handlingStrategy":"validation","validationCode":"def cryptography_ok() -> bool:\n    try:\n        from cryptography.x509.extensions import Extensions\n        return getattr(Extensions, 'get_extension_for_class', None) is not None\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    import urllib3.contrib.pyopenssl  # triggers validation\nexcept ImportError as e:\n    if 'cryptography' in str(e):\n        raise SystemExit('Upgrade cryptography: pip install -U cryptography')\n    raise","preventionTips":["Upgrade cryptography to a current release before using the pyOpenSSL shim.","Refresh TLS pins (cryptography + pyOpenSSL) together.","Drop the pyOpenSSL shim if you don't need it; use native ssl."],"tags":["ssl","dependencies","version","pyopenssl","tls"],"analyzedSha":"c8d039c1b743f0bf5ee136972c68350fd91d41f1","analyzedAt":"2026-08-04T20:12:33.219Z","schemaVersion":2}