Module 'lib' has no attribute 'x509_v_flag_cb_issuer_check'

avatar
Borislav Hadzhiev

Last updated: Apr 11, 2024
6 min

banner

# Module 'lib' has no attribute 'x509_v_flag_cb_issuer_check'

This article addresses the following 2 related errors:

  • AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
  • AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'

The error "AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'" occurs due to an incompatibility between the cryptography and PyOpenSSL packages.

To solve the error upgrade your version of the PyOpenSSL package and make sure your pip version is up-to-date.

module lib has no attribute x509 v flag cb issuer check

The first thing you should try is to upgrade your version of the PyOpenSSL package.

shell
pip install pyOpenSSL --upgrade # Or pip3 pip3 install pyOpenSSL --upgrade

upgrade pyopenssl package

Your error message should contain the following lines toward the end.

shell
File "C:\ProgramData\Anaconda3\lib\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'

Notice that the error message mentions the file in which the error occurred and the line (1537 in the example).

The path to the file in the example is the following:

  • C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\crypto.py

On macOS or Linux, your path might look something like this:

  • /usr/lib/python3/dist-packages/OpenSSL/crypto.py

The name of the file is crypto.py, however, the path in your case will likely be different.

If the error persists, you can try to:

  1. Open the specified file in a text editor.
  2. Comment out the specified line (1537 in the example error message) by prefixing it with a hash #.

The line is trying to the X509_V_FLAG_CB_ISSUER_CHECK attribute which is not available in the given version.

  1. Upgrade your version of the pyOpenSSL module
shell
pip install pyOpenSSL --upgrade # Or pip3 pip3 install pyOpenSSL --upgrade
  1. You can now uncomment the line and everything should work as expected.

# Try to reinstall the pyOpenSSL module with the --ignore-installed flag

If the error persists, try to reinstall the pyOpenSSL package with the --ignore-installed flag.

shell
pip install pyOpenSSL --ignore-installed # Or pip3 pip3 install pyOpenSSL --ignore-installed

reinstall package with ignore installed flag

The --ignore-installed option ignores the installed packages (and their dependencies) and overwrites them.

# Try to delete the OpenSSL folder from your machine

If the error persists, try to delete the OpenSSL folder from your machine.

Your error message should contain the following lines toward the end.

shell
File "C:\ProgramData\Anaconda3\lib\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'

Notice that the error message contains the path to the OpenSSL folder.

The path of the OpenSSL folder in the example is the following:

  • C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL

If you are on Windows, you can use the rd command to delete the OpenSSL folder.

cmd
# On Windows rd /s /q "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL"
Make sure to replace the path in the example with the path to the OpenSSL folder from your error message.

Once you delete the folder, install the pyOpenSSL module.

shell
pip install pyOpenSSL --upgrade # Or pip3 pip3 install pyOpenSSL --upgrade

If you are on macOS or Linux, you can use the rm -rf command.

shell
# On macOS and Linux sudo rm -rf <path_to_lib_python3.10>/site-packages/OpenSSL
Make sure to replace the path in the example with the path to the OpenSSL folder from your error message.

For example, on macOS, your path might look something like this:

  • /usr/lib/python3/dist-packages/OpenSSL

Once you delete the folder, install the pyOpenSSL module.

shell
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade

# Update your version of pip if the error persists

If the error persists, try to upgrade your version of pip.

Open your terminal and run one of the following commands to upgrade pip.

shell
# ๐Ÿ‘‡๏ธ On Linux or macOS python -m ensurepip --upgrade # ๐Ÿ‘‡๏ธ Using python 3 python3 -m ensurepip --upgrade # ๐Ÿ‘‡๏ธ On Windows py -m ensurepip --upgrade

If that doesn't work, use the official get-pip.py script.

To download the script from https://bootstrap.pypa.io/get-pip.py:

  1. Click on the link.
  2. Right-click and select "Save as" in your browser.
Open your terminal in the location where the get-pip.py file is downloaded and run the following command.
shell
# ๐Ÿ‘‡๏ธ On Linux or macOS python get-pip.py # ๐Ÿ‘‡๏ธ Using python 3 python3 get-pip.py # ๐Ÿ‘‡๏ธ On Windows py get-pip.py

The get-pip.py script uses bootstrapping logic to install pip.

You can also download the script using curl (if you have curl installed).

shell
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # ๐Ÿ‘‡๏ธ On Linux or macOS python get-pip.py --force-reinstall # ๐Ÿ‘‡๏ธ Using python 3 python3 get-pip.py --force-reinstall # ๐Ÿ‘‡๏ธ On Windows py get-pip.py --force-reinstall

I've written an article on how to install curl on Windows, in case you need to install it.

If you are on macOS or Linux and the error persists, try running the following commands.

shell
sudo apt remove python3-pip wget https://bootstrap.pypa.io/get-pip.py sudo python get-pip.py # or python3 sudo python3 get-pip.py

After you upgrade pip, make sure to upgrade the pyOpenSSL module.

shell
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade

upgrade pyopenssl package

# If you are on Ubuntu, uninstall the python3-openssl package

If you are on Ubuntu, try to uninstall the python3-openssl package.

Open your terminal and run the following command.

shell
sudo apt remove python3-openssl

After you uninstall the package, upgrade pyOpenSSL.

shell
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade

You can also try to reinstall the python3-openssl package if the issue persists.

shell
sudo apt install --reinstall python3-openssl

# Try to uninstall and reinstall the pyOpenSSL package

If the error persists, try to uninstall and reinstall the pyOpenSSL package.

  1. Open your terminal and run the following command to uninstall the module.
shell
pip uninstall pyOpenSSL # or with pip3 pip3 uninstall pyOpenSSL

Now, run the following command to reinstall the module.

shell
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade

# AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'

If you get the error "AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'", try to upgrade your cryptography and pyopenssl packages.

The error is caused due to incompatibility between some versions of the packages.

Open your terminal and run the following command.

shell
pip install pyOpenSSL cryptography --upgrade # or pip3 pip3 install pyOpenSSL cryptography --upgrade

upgrade cryptography and pyopenssl

After you upgrade the pyOpenSSL and cryptography packages, the error should be resolved.

The error is caused by cryptography version 39.0.0 and updating to version 41 should resolve it.

You can print the version of your cryptography module by running the pip show command.

shell
pip show cryptography # or with pip3 pip3 show cryptography

print cryptography version

# Try to downgrade cryptography to version 38.0.4

If the error persists, try to downgrade the cryptography module to version 38.0.4.

The error is caused by cryptography version 39.0.0, so downgrading should resolve the issue.

Open your terminal and run the following command.

shell
pip install cryptography==38.0.4 pip3 install cryptography==38.0.4 # or with python -m python -m pip install cryptography==38.0.4 python3 -m pip install cryptography==38.0.4 py -m pip install cryptography==38.0.4

pin your cryptography version

When you run the command, you might get an error that states "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed.".

However, even though the error is shown, the package is installed successfully.

Once you run the installation command, add the following line to your requirements.txt file.

requirements.txt
cryptography==38.0.4

You can print the version of your cryptography module by running the pip show command.

shell
pip show cryptography # or with pip3 pip3 show cryptography

verify cryptography module downgraded

If the error persists after downgrading cryptography, try to upgrade your pyOpenSSL version.

shell
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade

upgrade pyopenssl package

# Try to uninstall and reinstall the cryptography package

If the error persists, try to uninstall and reinstall the cryptography package.

  1. Open your terminal and run the following command to uninstall the module.
shell
pip uninstall pyOpenSSL cryptography # or with pip3 pip3 uninstall pyOpenSSL cryptography

uninstall and reinstall cryptography

Now, run the following command to reinstall the module.

shell
pip install pyOpenSSL cryptography --upgrade # or pip3 pip3 install pyOpenSSL cryptography --upgrade

upgrade cryptography

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev