Skip to content

Commit 2fa651c

Browse files
ShaneHarveyoh2fih
andauthored
PYTHON-4492 [v4.8] Fallback to stdlib ssl when pyopenssl import fails with AttributeError (#1675)
Co-authored-by: Esa Jokinen <[email protected]>
1 parent 23a3f3c commit 2fa651c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pymongo/ssl_support.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Support for SSL in PyMongo."""
1616
from __future__ import annotations
1717

18+
import warnings
1819
from typing import Optional
1920

2021
from pymongo.errors import ConfigurationError
@@ -23,7 +24,17 @@
2324

2425
try:
2526
import pymongo.pyopenssl_context as _ssl
26-
except ImportError:
27+
except (ImportError, AttributeError) as exc:
28+
if isinstance(exc, AttributeError):
29+
warnings.warn(
30+
"Failed to use the installed version of PyOpenSSL. "
31+
"Falling back to stdlib ssl, disabling OCSP support. "
32+
"This is likely caused by incompatible versions "
33+
"of PyOpenSSL < 23.2.0 and cryptography >= 42.0.0. "
34+
"Try updating PyOpenSSL >= 23.2.0 to enable OCSP.",
35+
UserWarning,
36+
stacklevel=2,
37+
)
2738
try:
2839
import pymongo.ssl_context as _ssl # type: ignore[no-redef]
2940
except ImportError:

0 commit comments

Comments
 (0)