Cryptography not installed · Issue #455 · oracle/python-oracledb (original) (raw)

  1. What versions are you using?
  2. Is it an error or a hang or a crash?
    It is an incorrect error message caused by misleading detection of the cryptography library.
  3. What error(s) or behavior you are seeing?
    The oracledb library currently tests the availability of the cryptography package by attempting to import it. However, this approach can lead to misleading error messages when the import fails for reasons unrelated to the package’s absence.

For example, if cryptography is already loaded in a way that prevents re-importing (such as in environments where duplicate loading is not supported), the import attempt may fail. In such cases, the error message incorrectly states that cryptography is not installed, even though it is present.

A concrete example of this issue occurs when using oracledb in combination with mod_wsgi. In such cases, the import of cryptography can fail with the following error:

from cryptography.hazmat.bindings._rust import x509 as rust_x509
ImportError: PyO3 modules compiled for CPython 3.8 or older may only be initialized once per interpreter process
This error is unrelated to the library being missing and is instead due to Python’s module loading restrictions. However, oracledb still incorrectly reports that cryptography is not installed.

  1. Does your application call init_oracle_client()?

Yes, but the issue occurs in Thin mode as well.

  1. Include a runnable Python script that shows the problem.

Proposed Improvement
Instead of treating any import failure as a missing library, the error handling should distinguish between:

ModuleNotFoundError – indicating that cryptography is genuinely missing.
Other ImportErrors – which may result from different issues, such as incompatible environments or duplicate loading.
Providing a more specific error message based on the actual cause of failure would help users diagnose the problem more effectively.