From 7e3b89e47828c9b22e2d6c58ebba2186a67b22ef Mon Sep 17 00:00:00 2001 From: Esa Jokinen Date: Wed, 12 Jun 2024 06:22:00 +0300 Subject: [PATCH] PYTHON-4492 Fallback to stdlib ssl when pyopenssl import fails with AttributeError caused by incompatibility between PyOpenSSL < 23.2.0 & cryptography >= 42.0.0. --- pymongo/ssl_support.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pymongo/ssl_support.py b/pymongo/ssl_support.py index 849fbf7018..6a5dd278d3 100644 --- a/pymongo/ssl_support.py +++ b/pymongo/ssl_support.py @@ -15,6 +15,7 @@ """Support for SSL in PyMongo.""" from __future__ import annotations +import warnings from typing import Optional from pymongo.errors import ConfigurationError @@ -23,7 +24,17 @@ try: import pymongo.pyopenssl_context as _ssl -except ImportError: +except (ImportError, AttributeError) as exc: + if isinstance(exc, AttributeError): + warnings.warn( + "Failed to use the installed version of PyOpenSSL. " + "Falling back to stdlib ssl, disabling OCSP support. " + "This is likely caused by incompatible versions " + "of PyOpenSSL < 23.2.0 and cryptography >= 42.0.0. " + "Try updating PyOpenSSL >= 23.2.0 to enable OCSP.", + UserWarning, + stacklevel=2, + ) try: import pymongo.ssl_context as _ssl # type: ignore[no-redef] except ImportError: