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

Question:

So recently I had to reinstall python due to 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 cant seem to find any information on this particular error.

For what it is worth – I am trying to pull google analytics info down via API call.

here is an output of the command prompt error

  File "C:AnalyticsPuritan_GoogleAnalyticsGoogle_ConversionsmcfTest.py", line 1, in <module>
    from apiclient.discovery import build
  File "C:ProgramDataAnaconda3libsite-packagesapiclient__init__.py", line 3, in <module>
    from googleapiclient import channel, discovery, errors, http, mimeparse, model
  File "C:ProgramDataAnaconda3libsite-packagesgoogleapiclientdiscovery.py", line 57, in <module>
    from googleapiclient import _auth, mimeparse
  File "C:ProgramDataAnaconda3libsite-packagesgoogleapiclient_auth.py", line 34, in <module>
    import oauth2client.client
  File "C:ProgramDataAnaconda3libsite-packagesoauth2clientclient.py", line 45, in <module>
    from oauth2client import crypt
  File "C:ProgramDataAnaconda3libsite-packagesoauth2clientcrypt.py", line 45, in <module>
    from oauth2client import _openssl_crypt
  File "C:ProgramDataAnaconda3libsite-packagesoauth2client_openssl_crypt.py", line 16, in <module>
    from OpenSSL import crypto
  File "C:ProgramDataAnaconda3libsite-packagesOpenSSL__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
  File "C:ProgramDataAnaconda3libsite-packagesOpenSSLcrypto.py", line 1517, in <module>
    class X509StoreFlags(object):
  File "C:ProgramDataAnaconda3libsite-packagesOpenSSLcrypto.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'
Asked By: Doug Coats

||

Answers:

Edit the crypto.py file mentioned in the stacktrace and remove the offending line by commenting it out with a #

Then upgrade latest version of PyOpenSSL.

pip install pip --upgrade
pip install pyopenssl --upgrade

Now you can re-add the commented line again and it should be working

Answered By: Robin Sving

on my ubuntu "20.04.5" I manage solving the error:

CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECKr

by re-installing 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.

Hope it helps somebody on day.

Answered By: Orsius

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.

Answered By: DarkSkull

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:

  1. Get 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
    
  2. Install pyOpenSSL from whl file.

    python3 -m easy_install pyOpenSSL-22.1.0-py3-none-any.whl
    

Thanks https://askubuntu.com/a/1429674

Answered By: yxzlwz

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
Answered By: miu

As all the above failed for me i used the trick here: https://askubuntu.com/a/1433089/497392

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

And then after a reboot:

pip install pyopenssl --upgrade
Answered By: Kjeld Flarup

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.

Answered By: Alexandr

pip3 install pyOpenSSL –upgrade

solved all my issues.

Answered By: hightest

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
Answered By: JDogMcSteezy

Below commands worked for me…

sudo pip3 install pyopenssl

sudo pip3 install pyopenssl –upgrade

Answered By: Nishant Kabariya

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.

  • sudo apt remove python3-pip followed by sudo apt install python3-pip
  • sudo pip install pyopenssl –upgrade
  • sudo python3 -m easy_install pyOpenSSL-22.0.0-py2.py3-none-any.whl
  • sudo pip install –force-reinstall "cryptography==38.0.4"

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
Answered By: Byte Insight

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
Answered By: bonifacio_kid
sudo apt remove python3-openssl
Answered By: mtwebster

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.

Answered By: Sudha
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.