Last updated: Apr 11, 2024
Reading timeยท6 min
This article addresses the following 2 related errors:
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.
The first thing you should try is to upgrade your version of the PyOpenSSL package.
pip install pyOpenSSL --upgrade # Or pip3 pip3 install pyOpenSSL --upgrade
Your error message should contain the following lines toward the end.
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:
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.
pyOpenSSL
modulepip install pyOpenSSL --upgrade # Or pip3 pip3 install pyOpenSSL --upgrade
pyOpenSSL
module with the --ignore-installed
flagIf the error persists, try to reinstall the pyOpenSSL
package with the
--ignore-installed
flag.
pip install pyOpenSSL --ignore-installed # Or pip3 pip3 install pyOpenSSL --ignore-installed
The --ignore-installed option ignores the installed packages (and their dependencies) and overwrites them.
If the error persists, try to delete the OpenSSL folder from your machine.
Your error message should contain the following lines toward the end.
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.
# On Windows rd /s /q "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL"
Once you delete the folder, install the pyOpenSSL
module.
pip install pyOpenSSL --upgrade # Or pip3 pip3 install pyOpenSSL --upgrade
If you are on macOS or Linux, you can use the rm -rf
command.
# On macOS and Linux sudo rm -rf <path_to_lib_python3.10>/site-packages/OpenSSL
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.
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade
If the error persists, try to upgrade your version of pip
.
Open your terminal and run one of the following commands to upgrade pip.
# ๐๏ธ 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:
get-pip.py
file is downloaded and run the following command.# ๐๏ธ 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).
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.
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.
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade
python3-openssl
packageIf you are on Ubuntu, try to uninstall the python3-openssl
package.
Open your terminal and run the following command.
sudo apt remove python3-openssl
After you uninstall the package, upgrade pyOpenSSL
.
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade
You can also try to reinstall the python3-openssl
package if the issue
persists.
sudo apt install --reinstall python3-openssl
pyOpenSSL
packageIf the error persists, try to uninstall and reinstall the pyOpenSSL
package.
pip uninstall pyOpenSSL # or with pip3 pip3 uninstall pyOpenSSL
Now, run the following command to reinstall the module.
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade
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.
pip install pyOpenSSL cryptography --upgrade # or pip3 pip3 install pyOpenSSL cryptography --upgrade
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.
pip show cryptography # or with pip3 pip3 show cryptography
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.
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
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.".
Once you run the installation command, add the following line to your
requirements.txt
file.
cryptography==38.0.4
You can print the version of your cryptography
module by running the
pip show
command.
pip show cryptography # or with pip3 pip3 show cryptography
If the error persists after downgrading cryptography
, try to upgrade your
pyOpenSSL
version.
pip install pyOpenSSL --upgrade # or pip3 pip3 install pyOpenSSL --upgrade
cryptography
packageIf the error persists, try to uninstall and
reinstall the cryptography
package.
pip uninstall pyOpenSSL cryptography # or with pip3 pip3 uninstall pyOpenSSL cryptography
Now, run the following command to reinstall the module.
pip install pyOpenSSL cryptography --upgrade # or pip3 pip3 install pyOpenSSL cryptography --upgrade
You can learn more about the related topics by checking out the following tutorials: