Introducing Livops 2.0! Promo codeCEOgives you 8,000 so‘m on your balance.What’s new

AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK': how to fix it

AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK', raised from OpenSSL/crypto.py, means an old pyOpenSSL is installed next to a newer cryptography. pyOpenSSL 20.0.1 and older read that constant as they load, and cryptography 38.0.0 removed it. The same mismatch shows as 'OpenSSL_add_all_algorithms', 'X509_V_FLAG_NOTIFY_POLICY' or 'GEN_EMAIL'. Upgrade pyOpenSSL, or uninstall it if nothing needs it, and pin versions that fit together.

By Livops team, the people who build and run LivopsUpdated

The app, a script or even pip stops as soon as something imports OpenSSL. With pyOpenSSL 20.0.1 installed next to cryptography 38 or newer, the traceback ends in pyOpenSSL’s own crypto.py[3][6]:

  File ".../site-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
  File ".../site-packages/OpenSSL/crypto.py", line 1556, in <module>
    class X509StoreFlags(object):
  File ".../site-packages/OpenSSL/crypto.py", line 1577, in X509StoreFlags
    CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

The same mismatch also shows up with other names after has no attribute. This page explains what lib is and why it lost the name, how to tell which versions you have, the fixes (upgrade pyOpenSSL, or remove it), and how to get a working pip back when the error breaks pip too.

What does the error mean?

pyOpenSSL is a Python wrapper around the OpenSSL library[21]. It does not compile its own bindings: its _util.py creates cryptography’s Binding object and takes its lib attribute[5], and crypto.py imports that as _lib[3]. lib is cryptography’s compiled interface to OpenSSL: the constants and functions cryptography chose to expose.

pyOpenSSL 20.0.1 reads a list of constants from _lib in the body of the X509StoreFlags class, which runs the moment OpenSSL.crypto is imported; the last one is X509_V_FLAG_CB_ISSUER_CHECK[3]. pyOpenSSL 21.0.0 no longer reads it[4]. On the cryptography side, the constant is still declared in 37.0.1[7] and gone from 38.0.0[8]. cryptography 38.0.0, released on 6 September 2022, says it removed several legacy symbols from its OpenSSL bindings and that users of pyOpenSSL versions older than 22.0 will need to upgrade[2]. It had happened once before: 37.0.1, released a day after 37.0.0, restored some legacy symbols for older pyOpenSSL users, with the warning that they would be removed again[2].

So the error needs two things at once: a pyOpenSSL from before 21.0.0, and a cryptography from 38.0.0 on.

The same mismatch, other names

pyOpenSSL stops on the first name the installed cryptography no longer has, so which name you see depends on both versions. The ones people hit:

The error names Read by pyOpenSSL as it loads Gone from cryptography’s bindings in
X509_V_FLAG_CB_ISSUER_CHECK 20.0.1 and older[3] 38.0.0[7][8]
OpenSSL_add_all_algorithms 22.0.0 and older, at the end of crypto.py[9] 39.0.0[10][11]
X509_V_FLAG_NOTIFY_POLICY 23.1.1 and older[12]; pyOpenSSL 23.2.0 removed X509StoreFlags.NOTIFY_POLICY[1] 42.0.0[13][14]
GEN_EMAIL 25.1.0, for one, in the X509Extension class[15] 49.0.0[16][17]

Whichever row you are in, the cause is a pyOpenSSL older than the cryptography next to it, and the fix below is the same.

How the two got out of step

Old pyOpenSSL releases set only a minimum cryptography: 20.0.1 asks for cryptography>=3.2[18] and 22.0.0 for cryptography>=35.0[19]. A fresh install of a requirements.txt that pins pyopenssl==20.0.1 and leaves cryptography out gets the newest cryptography, and the newest has none of the names in the table.

pyOpenSSL 22.1.0 started pinning releases against cryptography major versions to prevent future breakage[1]: it asks for cryptography>=38.0.0,<39[20]. The current pyOpenSSL, 26.5.1, asks for cryptography>=49.0.0,<52[21]. With those ranges pip does not choose a mismatched pair by itself, so when you see this error with a newer pyOpenSSL, something installed cryptography around it. pip check verifies that installed packages have compatible dependencies and names the ones that do not[29]:

.venv/bin/python -m pip check
.venv/bin/python -m pip show pyopenssl cryptography

Fix 1: upgrade pyOpenSSL

.venv/bin/python -m pip install --upgrade pyopenssl

--upgrade takes the newest pyOpenSSL; by default its dependencies are upgraded only when they do not satisfy the new version’s requirements[28], so pip moves cryptography only if it has to. Then write both versions into requirements.txt, so the next fresh install gets the same pair. On PyPI today that is[21][22]:

pyopenssl==26.5.1
cryptography==51.0.1

Better still, pin what you tested: pip freeze writes out a requirements file of pinned versions, not only for the top-level packages but for everything under them[33]:

.venv/bin/python -m pip freeze > requirements.txt

pyOpenSSL removes deprecated APIs from time to time: 23.3.0 removed load_pkcs7 and load_pkcs12, for example, and 26.3.0 removed X509Req[1]. If your own code calls pyOpenSSL directly, read its changelog for the versions you skip, and test before you deploy.

Fix 2: remove pyOpenSSL if nothing needs it

Many projects carry pyopenssl from years ago, when Requests used it. Until 2.24.0, Requests used pyOpenSSL whenever it was installed; since 2.24.0, only if Python has no ssl module or no SNI support[23]. In 2.26.0 the requests[security] extra became a no-op install, and pyOpenSSL is no longer the recommended secure option for Requests[23].

Check whether anything still depends on it:

.venv/bin/python -m pip show pyopenssl

pip prints the Required-by line with the installed packages that require it[30]. If it is empty and your code has no import OpenSSL, uninstall it and delete its line from requirements.txt:

.venv/bin/python -m pip uninstall pyopenssl

If another package is listed under Required-by, upgrade that package too: its newer releases may ask for a newer pyOpenSSL, or not need it at all. pyOpenSSL’s own page says the Python Cryptographic Authority strongly suggests using cryptography where possible, and that code using pyOpenSSL for anything other than making a TLS connection should move to cryptography[21].

When pip itself fails with this error

On an older system, pip install itself can print the same traceback. pip 20.1.1 vendors Requests 2.23.0 and urllib3 1.25.8[25]. On anything but Windows, its copy of Requests imports urllib3’s pyOpenSSL support whenever it is loaded, inside a try that catches only ImportError[24], and that module runs import OpenSSL.SSL[26]. An old pyOpenSSL next to a new cryptography raises AttributeError, which that try does not catch, so pip install stops on it before it installs anything. pip 20.2 changed the check: it loads pyOpenSSL only when Python’s ssl module reports no SNI support[27].

A pip that cannot install cannot install its own fix, so work around it:

  • Use a virtual environment. A venv gets access to the system site-packages only if you create it with --system-site-packages[32], so the system’s old pyOpenSSL is not visible inside it, and venv bootstraps pip into the new environment with ensurepip[32]:

    python3 -m venv .venv
    .venv/bin/python -m pip install --upgrade pip
    .venv/bin/python -m pip install -r requirements.txt

    This is the fix for an app: run it from its own environment, not from the system Python.

  • Repair the system’s pip. pip’s maintainers support two ways to install pip: python -m ensurepip --upgrade, and the get-pip.py script from https://bootstrap.pypa.io/get-pip.py[31]. A current pip loads pyOpenSSL only without SNI[27], so once it is installed you can run python3 -m pip install --upgrade pyopenssl, or uninstall pyOpenSSL.

  • If the old pyOpenSSL came from your operating system’s packages, upgrade or remove it with the same package manager rather than with pip. If pip answers with externally-managed-environment, see that error’s page.

On Livops

  • Dependencies are installed on the server. Livops installs your requirements.txt itself on each build, so an old pyopenssl== pin with no cryptography pin can resolve to the newest cryptography on any deploy. Pin both, as in Fix 1, and the next deploy installs that pair.

  • Do not upload your .venv. When you upload a folder, venv and .venv are dropped automatically; we install dependencies ourselves.

  • A failed start. The error stops the app as it imports pyOpenSSL, so the deploy fails as start_failed. A web app’s previous version keeps running; a bot’s previous version was stopped first, so the bot is down until a deploy succeeds. The traceback is on the Logs page, and the assistant can read the log and explain what happened. See The app did not start.

  • Python commands use the project’s environment. A start command of your own goes in livops.json as "start" and uses the project’s .venv, for example .venv/bin/python main.py. See Frameworks and livops.json.

  • Choose the Python. Livops runs Python 3.10 to 3.14. A .python-version file at the project root pins it:

    3.12

A Python web app costs 39 credits a month. If the app starts but HTTPS calls fail with CERTIFICATE_VERIFY_FAILED, that is a different problem: see SSL: CERTIFICATE_VERIFY_FAILED in Python.

Questions

What causes module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'?

An old pyOpenSSL with a newer cryptography. pyOpenSSL 20.0.1 and older read the constant X509_V_FLAG_CB_ISSUER_CHECK from cryptography's OpenSSL bindings when they load. cryptography 38.0.0 removed it, so importing OpenSSL fails before your code runs.

What is lib in the message?

It is cryptography's compiled OpenSSL bindings. pyOpenSSL creates cryptography's Binding object and keeps its lib attribute, which crypto.py uses as _lib. When pyOpenSSL asks lib for a name the installed cryptography no longer provides, Python raises AttributeError.

Should I downgrade cryptography or upgrade pyOpenSSL?

Upgrade pyOpenSSL. Since 22.1.0 it pins the cryptography major versions it works with, so pip installs a matching cryptography with it. Holding cryptography back to fit an old pyOpenSSL only postpones the same error to the next upgrade.

Do I need pyOpenSSL at all?

Often not. Requests used pyOpenSSL whenever it was installed until 2.24.0; since then only when Python has no ssl module or no SNI support, and the requests[security] extra installs nothing since 2.26.0. Run pip show pyopenssl: if its Required-by line is empty and your code does not import OpenSSL, uninstall it.

Why does pip itself fail with the same error?

pip 20.1.1, on any system but Windows, tries to load urllib3's pyOpenSSL support whenever its copy of Requests is imported, and catches only ImportError. An old pyOpenSSL raises AttributeError instead, so pip install stops. pip 20.2 and later load pyOpenSSL only when Python's ssl module lacks SNI. Use a virtual environment, or install a current pip.

The error names X509_V_FLAG_NOTIFY_POLICY or OpenSSL_add_all_algorithms. Is it the same problem?

Yes. pyOpenSSL stops on the first constant or function the installed cryptography no longer has. pyOpenSSL 22.0.0 and older call OpenSSL_add_all_algorithms, removed in cryptography 39.0.0; 23.1.1 and older read X509_V_FLAG_NOTIFY_POLICY, removed in 42.0.0. The fix is the same: upgrade pyOpenSSL.

Which Python versions does Livops run?

Python 3.10 to 3.14. Put the version in a .python-version file at the project root, for example 3.12.

Sources

  1. pyOpenSSL — Changelog (pyopenssl.org). Checked .
  2. cryptography — Changelog (cryptography.io). Checked .
  3. pyOpenSSL source — src/OpenSSL/crypto.py (20.0.1) (github.com). Checked .
  4. pyOpenSSL source — src/OpenSSL/crypto.py (21.0.0) (github.com). Checked .
  5. pyOpenSSL source — src/OpenSSL/_util.py (20.0.1) (github.com). Checked .
  6. pyOpenSSL source — src/OpenSSL/__init__.py (20.0.1) (github.com). Checked .
  7. cryptography source — src/_cffi_src/openssl/x509_vfy.py (37.0.1) (github.com). Checked .
  8. cryptography source — src/_cffi_src/openssl/x509_vfy.py (38.0.0) (github.com). Checked .
  9. pyOpenSSL source — src/OpenSSL/crypto.py (22.0.0) (github.com). Checked .
  10. cryptography source — src/_cffi_src/openssl/evp.py (38.0.4) (github.com). Checked .
  11. cryptography source — src/_cffi_src/openssl/evp.py (39.0.0) (github.com). Checked .
  12. pyOpenSSL source — src/OpenSSL/crypto.py (23.1.1) (github.com). Checked .
  13. cryptography source — src/_cffi_src/openssl/x509_vfy.py (41.0.7) (github.com). Checked .
  14. cryptography source — src/_cffi_src/openssl/x509_vfy.py (42.0.0) (github.com). Checked .
  15. pyOpenSSL source — src/OpenSSL/crypto.py (25.1.0) (github.com). Checked .
  16. cryptography source — src/_cffi_src/openssl/x509v3.py (48.0.0) (github.com). Checked .
  17. cryptography source — src/_cffi_src/openssl/x509v3.py (49.0.0) (github.com). Checked .
  18. pyOpenSSL source — setup.py (20.0.1) (github.com). Checked .
  19. pyOpenSSL source — setup.py (22.0.0) (github.com). Checked .
  20. pyOpenSSL source — setup.py (22.1.0) (github.com). Checked .
  21. PyPI — pyOpenSSL (pypi.org). Checked .
  22. PyPI — cryptography (pypi.org). Checked .
  23. Requests — Release History (github.com). Checked .
  24. pip source — src/pip/_vendor/requests/__init__.py (20.1.1) (github.com). Checked .
  25. pip source — src/pip/_vendor/vendor.txt (20.1.1) (github.com). Checked .
  26. urllib3 source — src/urllib3/contrib/pyopenssl.py (1.25.8) (github.com). Checked .
  27. pip source — src/pip/_vendor/requests/__init__.py (20.2) (github.com). Checked .
  28. pip docs — pip install (pip.pypa.io). Checked .
  29. pip docs — pip check (pip.pypa.io). Checked .
  30. pip source — src/pip/_internal/commands/show.py (github.com). Checked .
  31. pip docs — Installation (pip.pypa.io). Checked .
  32. Python docs — venv (docs.python.org). Checked .
  33. pip docs — Repeatable Installs (pip.pypa.io). Checked .

Put your project online today

Connect GitHub or drop a folder. No card is asked for.

Deploy your Python app

Got a question? — @livops_uz