diff --git a/seleniumbase/core/mysql.py b/seleniumbase/core/mysql.py index fca49281..1a2edb6c 100644 --- a/seleniumbase/core/mysql.py +++ b/seleniumbase/core/mysql.py @@ -19,6 +19,18 @@ class DatabaseManager: constants.PipInstall.FINDLOCK ) with pip_find_lock: + if sys.version_info >= (3, 7) and sys.version_info < (3, 9): + # Fix bug in newer cryptography for Python 3.7 and 3.8: + # "pyo3_runtime.PanicException: Python API call failed" + # (Match the version needed for pdfminer.six functions) + try: + import cryptography + if cryptography.__version__ != "39.0.2": + shared_utils.pip_install( + "cryptography", version="39.0.2" + ) + except Exception: + shared_utils.pip_install("cryptography", version="39.0.2") try: import cryptography # noqa: F401 import pymysql diff --git a/seleniumbase/fixtures/base_case.py b/seleniumbase/fixtures/base_case.py index b6fc4f0b..c527a3fa 100644 --- a/seleniumbase/fixtures/base_case.py +++ b/seleniumbase/fixtures/base_case.py @@ -6380,6 +6380,22 @@ class BaseCase(unittest.TestCase): constants.PipInstall.FINDLOCK ) with pip_find_lock: + if ( + sys.version_info >= (3, 7) + and sys.version_info < (3, 9) + ): + # Fix bug in newer cryptography for Python 3.7 and 3.8: + # "pyo3_runtime.PanicException: Python API call failed" + try: + import cryptography + if cryptography.__version__ != "39.0.2": + shared_utils.pip_install( + "cryptography", version="39.0.2" + ) + except Exception: + shared_utils.pip_install( + "cryptography", version="39.0.2" + ) try: from pdfminer.high_level import extract_text except Exception: diff --git a/setup.py b/setup.py index 8f9218bd..8b02b78c 100755 --- a/setup.py +++ b/setup.py @@ -264,7 +264,8 @@ setup( 'pdfminer.six==20211012;python_version<"3.7"', 'pdfminer.six==20221105;python_version>="3.7"', 'cryptography==36.0.2;python_version<"3.7"', - 'cryptography==41.0.3;python_version>="3.7"', + 'cryptography==39.0.2;python_version>="3.7" and python_version<"3.9"', # noqa: E501 + 'cryptography==41.0.3;python_version>="3.9"', "cffi==1.15.1", "pycparser==2.21",