Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

pip or Python crashes on X509_V_FLAG_CB_ISSUER_CHECK at import

Your error

AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'2 more lines it can show

Fix it fast

Most common cause, 1 of 2

pyOpenSSL in the environment is too old for its cryptography

Upgrade pyOpenSSL in that environment.

Fix
python -m pip install --upgrade pyopenssl
python -m pip check
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK' means an old pyOpenSSL is being imported with a newer cryptography that no longer exposes that constant. In a virtual environment, upgrade pyOpenSSL; 26.4 accepts only cryptography 49 to 50. On a distro Python, where apt owns pyOpenSSL, install your packages in a venv instead.

  • Applies to pyOpenSSL 26.4.0, cryptography 50.0, pip 26.3, Ubuntu 22.04 (python3-openssl 21.0.0)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print where cryptography loads from and set it beside the OpenSSL/crypto.py path in the traceback. Both inside one virtual environment points to cause 1; OpenSSL under /usr/lib/python3/dist-packages, the folder apt manages, with cryptography under /usr/local points to cause 2.

Run this first
python3 -c "import cryptography; print(cryptography.__version__, cryptography.__file__)"

Then find the line you see in this list and open its fix:

  1. 1pyOpenSSL in the environment is too old for its cryptographyOpenSSL/crypto.py sits in the same site-packages as cryptography, and pip show reports pyOpenSSL around 20 or 21 next to a much newer cryptography
  2. 2apt's pyOpenSSL meets a cryptography installed later with pipThe traceback runs through /usr/lib/python3/dist-packages/OpenSSL and, on Ubuntu 20.04, through /usr/share/python-wheels/urllib3, so even pip itself fails

What does the error look like?

  • AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
  • CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
  • File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags

Cause 1 of 2

pyOpenSSL in the environment is too old for its cryptography

You seeOpenSSL/crypto.py sits in the same site-packages as cryptography, and pip show reports pyOpenSSL around 20 or 21 next to a much newer cryptography

Check

pyOpenSSL reads X509_V_FLAG_CB_ISSUER_CHECK from cryptography's bindings when OpenSSL.crypto is imported, and newer cryptography builds dropped it. In the pyOpenSSL tracker, the maintainers trace this exact AttributeError to mixing versions and advise moving to the latest pyOpenSSL.

Check
python -m pip show pyopenssl cryptography | grep -E "^(Name|Version)"

Fix

Upgrade pyOpenSSL in that environment. Since 22.1.0 every pyOpenSSL release pins a matching range of cryptography, so pip pulls a compatible pair. Pinning cryptography back also stops the error, but it leaves you without security fixes.

Fix
python -m pip install --upgrade pyopenssl
python -m pip check

Verify

OpenSSL imports cleanly and prints its version.

Verify
python -c "import OpenSSL; print(OpenSSL.__version__)"

Confirmed by github.com

Did this fix it?

Cause 2 of 2

apt's pyOpenSSL meets a cryptography installed later with pip

You seeThe traceback runs through /usr/lib/python3/dist-packages/OpenSSL and, on Ubuntu 20.04, through /usr/share/python-wheels/urllib3, so even pip itself fails

Check

The distribution's own software depends on the python3-openssl and python3-cryptography versions apt installed. Running sudo pip install --upgrade cryptography, or installing anything that pulls it in, replaces only one half. cryptography's maintainers explain that an outdated pip with an outdated urllib3 then loads the old pyOpenSSL automatically, which is why pip breaks too.

Check
ls -d /usr/local/lib/python3*/dist-packages/cryptography*

Fix

Stop mixing sources. Both the pip and cryptography maintainers point to a virtual environment, which keeps the packages you install, and a current pip, apart from the ones apt manages.

Fix
python3 -m venv ~/venvs/app
~/venvs/app/bin/python -m pip install --upgrade pip
~/venvs/app/bin/python -m pip install -r requirements.txt

Verify

Commands run through the venv's python finish, and the traceback no longer mentions dist-packages/OpenSSL.

Verify
~/venvs/app/bin/python -m pip --version

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Never run sudo pip install on a distribution's Python; apt and pip each assume they own every package there.
  • Keep pyopenssl in the same lock file as cryptography so the pair always moves together.
  • Run python -m pip check in CI after installs; it exits non-zero when an installed package's dependencies are not compatible.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.