Reputation: 7117
Recently I had to reinstall Python due to a corrupt executable. This made one of our Python scripts bomb with the following error:
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
The line of code that caused it to bomb was:
from apiclient.discovery import build
I tried pip uninstalling and pip upgrading the google-api-python-client, but I can’t seem to find any information on this particular error.
For what it is worth, I am trying to pull Google Analytics information down via an API call.
Here is an output of the command prompt error:
File "C:\Analytics\Puritan_GoogleAnalytics\Google_Conversions\mcfTest.py", line 1, in <module>
from apiclient.discovery import build
File "C:\ProgramData\Anaconda3\lib\site-packages\apiclient\__init__.py", line 3, in <module>
from googleapiclient import channel, discovery, errors, http, mimeparse, model
File "C:\ProgramData\Anaconda3\lib\site-packages\googleapiclient\discovery.py", line 57, in <module>
from googleapiclient import _auth, mimeparse
File "C:\ProgramData\Anaconda3\lib\site-packages\googleapiclient\_auth.py", line 34, in <module>
import oauth2client.client
File "C:\ProgramData\Anaconda3\lib\site-packages\oauth2client\client.py", line 45, in <module>
from oauth2client import crypt
File "C:\ProgramData\Anaconda3\lib\site-packages\oauth2client\crypt.py", line 45, in <module>
from oauth2client import _openssl_crypt
File "C:\ProgramData\Anaconda3\lib\site-packages\oauth2client\_openssl_crypt.py", line 16, in <module>
from OpenSSL import crypto
File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\crypto.py", line 1517, in <module>
class X509StoreFlags(object):
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'
Upvotes: 189
Views: 343418
Reputation: 2551
As all the previous answers failed for me, I used the trick in module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK':
sudo apt remove python3-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
And then after a reboot (Starting a new shell may be enough, see comments):
pip install pyopenssl --upgrade
Upvotes: 171
Reputation: 11
To solve it, I resolved by taking the last line that mentions the installation of the OpenSSL library, removing the folder, and installing the previous version:
File "/home/azureuser/.local/lib/python3.8/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import SSL, crypto
File "/home/azureuser/.local/lib/python3.8/site-packages/OpenSSL/SSL.py", line 34, in <module>
from OpenSSL.crypto import (
File "/home/azureuser/.local/lib/python3.8/site-packages/OpenSSL/crypto.py"
$ sudo rm -rf /home/azureuser/.local/lib/python3.8/site-packages/OpenSSL
And installing version 22.0.0 which fixes this issue:
$ pip install pyOpenSSL==22.0.0
Upvotes: 1
Reputation: 8126
I would just remove the package
sudo rm -rf /usr/lib/python3/dist-packages/OpenSSL
Upvotes: 2
Reputation: 3350
Upgrade the latest version of PyOpenSSL.
python3 -m pip install pip --upgrade
pip install pyopenssl --upgrade
Upvotes: 308
Reputation: 101
Thank you for the suggestions. Once I realized the issue was the OpenSSL implementation, I just upgraded it using APT as follows:
apt-get install python3-openssl
This will resolve the issue system-wide as my Python environment is maintained by the distribution.
Upvotes: 2
Reputation: 941
The issue in this case was an unneeded OpenSSL installed that made the conflict and broke/block pip. The problem was solved when manual deleting the OpenSSL folder within site-packages folder.
For example, I deleted this folder in venv: venv/bin/python3.8/site-packages/OpenSSL
And fixed the pip issue globally: usr/lib/python3.8/site-packages/OpenSSL
Note: I found that due to this error, pip was broken and could not install or remove. After this solution, I could install new packages and import packages that may install new one.
Upvotes: 0
Reputation: 41
If you got this error when using pip, try this:
rm -rf <python_path>/site-packages/OpenSSL
The problem will be solved.
Upvotes: 4
Reputation: 41
The below commands worked for me...
sudo pip3 install pyopenssl
sudo pip3 install pyopenssl --upgrade
Upvotes: 4
Reputation: 185
For me, earlier answers can't help me as I meet this problem for all pip commands, even pip3 -V
. But I solved it by:
Get the URL from https://pypi.org/project/pyOpenSSL/#files if you need the latest version.
wget https://files.pythonhosted.org/packages/00/3f/ea5cfb789dddb327e6d2cf9377c36d9d8607af85530af0e7001165587ae7/pyOpenSSL-22.1.0-py3-none-any.whl
Install pyOpenSSL from the wheel file.
python3 -m easy_install pyOpenSSL-22.1.0-py3-none-any.whl
Thanks module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'.
Upvotes: 11
Reputation: 1029
On my Ubuntu 20.04.5 (Focal Fossa), I managed to solve the error:
CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK\r
by reinstalling the following packages:
apt-get --reinstall install python-apt
apt-get --reinstall install apt-transport-https
apt-get install build-essential libssl-dev libffi-dev python-dev
I do not use pip as I received this error message using Ansible playbook and wasn't able to reach the servers anymore.
Upvotes: 11
Reputation: 1089
I got the same issue using Certbot, the right version was not the latest, so : pip3 install pyOpenSSL==23.1.1
Upvotes: 1
Reputation: 12360
If you don't have sudo
rights the --user
option might do the trick:
wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py --user
python3 -m pip install pyopenssl --upgrade --user
Upvotes: 1
Reputation: 1
For me, issue resolved by changing snowflake-connector-python package version from 2.7.1 to latest version in requirements.txt file of Azure function app.
Upvotes: 0
Reputation: 1063
I also encountered this error while installing Flask and firebase-admin on Ubuntu 20.04. The following commands solved my problem. First I removed OpenSSL using this command.
sudo rm -rf /usr/lib/python3/dist-packages/OpenSSL
sudo pip3 install pyopenssl
sudo pip3 install pyopenssl --upgrade
Upvotes: 84
Reputation: 1154
I stumbled into this problem this morning trying to install weasyprint after a system update and restart. Commenting out the line containing
X509_V_FLAG_CB_ISSUER_CHECK
in /usr/lib/python3/dist-packages/OpenSSL/crypto.py resulted in a further error
AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'
None of the suggested fixes would work for me.
I found this module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK' but it didn't add to anything I already knew. I found this AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms' but it comes with WARNINGS for people running on desktops and it causing significant system wide issues.
I tried upgrading OpenSSL via easy_install but the wheel could not be found and there was a depreciation warning. Eventually I came back to the comment by @Alexandr who said just remove OpenSSL with rm.
sudo rm -rf /usr/lib/python3/dist-packages/OpenSSL
From here I attempted to reinstall OpenSSL but found it was already statisfied. Maybe an older package was blocking and this was the root of the problem?
sudo pip install pyopenssl
Requirement already satisfied: pyopenssl in /usr/lib/python3/dist-packages (19.0.0)
I then upgraded pip and was able to install WeasyPrint which I hope confirms I have solved this issue.
pip install pip --upgrade
Successfully installed pip-22.3.1
pip install weasyprint
Successfully installed Pyphen-0.13.2 ... weasyprint-57.2 zopfli-0.2.2
Upvotes: 6
Reputation: 259
Thanks to the answers above I was able to solve the same problem. I use pipenv to manage my environment. The issue arose after upgrading my cryptography module.
The fix (for me):
pipenv update pyOpenSSL
Upvotes: 0
Reputation: 81
I've tried upgrading pip and installing another version of pyOpenSSL
from whl file, but that didn't work. The only thing that helped is removing the entire folder with OpenSSL module like that rm -rf ...python-3.8.10/lib/python3.8/site-packages/OpenSSL
and then doing all the thing you need.
Upvotes: 2
Reputation: 1304
If pip
/ pip3
is completely broken and nothing of the other option work (as described by @DarkSkull), then the line in the crypto.py
file that's causing the issue has to be deleted or commented out.
Here's an automated way of doing it:
python_openssl_crypto_file="/usr/lib/python3/dist-packages/OpenSSL/crypto.py"
search_term="CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK"
cb_issuer_check_line_number="$(awk "/$search_term/ {print FNR}" $python_openssl_crypto_file)"
sed -i "${cb_issuer_check_line_number}s/.*/ # $search_term/" $python_openssl_crypto_file
Upvotes: 0
Reputation: 1085
If you have pip completely broken, as @sgdesmet propose in a comment, the only option to resolve this issue is
"Edit the crypto.py file and remove the offending line by commenting it out with a #"
No other solutions work with me.
Upvotes: 1