Skip to content

Resolve AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

Problem Statement

When working with Python libraries that depend on OpenSSL (like google-api-python-client or oauth2client), you may encounter this error:
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
The error typically occurs during imports, breaking your application. Common scenarios include:

  • After reinstalling or updating Python
  • When using Google APIs (from apiclient.discovery import build)
  • After environment changes or system updates
  • When pip itself becomes unusable due to OpenSSL issues

Root Cause

The error originates from an incompatibility between the pyOpenSSL package and your Python environment. Versions <19.1.0 contain a deprecated attribute (X509_V_FLAG_CB_ISSUER_CHECK) removed in newer OpenSSL libraries.

1. Upgrade pyOpenSSL (Standard Fix)

Update pyOpenSSL to the latest compatible version:

bash
pip install --upgrade pyOpenSSL

For Python 3 environments:

bash
pip3 install --upgrade pyOpenSSL

If the previous command fails, reinstall cryptography dependencies:

bash
pip install --force-reinstall cryptography pyOpenSSL

2. Reinstall pip and Upgrade pyOpenSSL

Use this if pip is broken or the standard upgrade fails:

bash
python3 -m pip uninstall pip
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
pip install --upgrade pyOpenSSL
batch
python -m pip uninstall pip
curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install --upgrade pyOpenSSL

3. Manual Removal and Reinstallation

If dependency conflicts persist, manually remove the problematic package:

DANGER

This permanently deletes files. Use only if previous solutions fail.

::: code-group-item Linux/Global

bash
sudo rm -rf /usr/lib/python3/dist-packages/OpenSSL
pip3 install --upgrade pyOpenSSL

::: ::: code-group-item User/venv

bash
rm -rf ~/.local/lib/python3.*/site-packages/OpenSSL
pip install --user --upgrade pyOpenSSL

::: ::: code-group-item Windows

batch
# Find your Python path with:
python -c "import site; print(site.getsitepackages())"

Then delete the detected OpenSSL folder manually :::

4. Install a Specific pyOpenSSL Version

If the latest version causes issues, try a known compatible version:

bash
pip install pyOpenSSL==22.0.0

5. System Package Manager (Ubuntu/Debian)

For system-managed Python environments:

bash
sudo apt update
sudo apt install --reinstall python3-openssl
Complete Error Traceback Example
python
File "app.py", line 1, in <module>
  from apiclient.discovery import build
File "site-packages/apiclient/__init__.py", line 3, in <module>
  ...
File "site-packages/OpenSSL/crypto.py", line 1537, in X509StoreFlags
  CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

Solution Comparison Table

MethodUse CaseRisk Level
Upgrade pyOpenSSLFirst troubleshooting stepLow
Reinstall pipBroken pip functionalityMedium
Manual RemovalStubborn installation conflictsHigh
Specific Version InstallationLatest version incompatibilitiesLow
System Package ManagerSystem-managed Python (Debian/Ubuntu)Low

Preventing Future Issues

  • Isolate projects using virtual environments (venv or conda)
  • Pin dependencies in requirements.txt:
    text
    pyOpenSSL==23.2.0
    cryptography==41.0.7
  • Update packages regularly:
    bash
    pip list --outdated  # Check outdated packages
    pip install --upgrade `pip list --outdated | grep -v '^\-e' | cut -d = -f 1`

Pro Tip

After applying fixes, verify with:

bash
python -c "from OpenSSL import crypto; print(crypto.__version__)"

This confirms pyOpenSSL imports correctly.

Conclusion

The X509_V_FLAG_CB_ISSUER_CHECK error indicates an outdated pyOpenSSL installation. Start with upgrading pyOpenSSL (pip install --upgrade pyOpenSSL). If that fails, progress through reinstalling pip, manual cleanup, or version-specific installations. For system-managed Python, use your OS package manager. Always test in virtual environments to avoid system-wide conflicts.