AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'. AWS sam build failure.
I'm getting below error after installing latest version of cryptography by using requirements.txt file in AWS deployment.
import OpenSSL.SSL
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/OpenSSL/crypto.py", line 3268, in <module>
_lib.OpenSSL_add_all_algorithms()
**_AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'_**
versions used during installation-
cryptography-39.0.0
Python- 3.9
cffi--1.15.1
pip-22.3.1
setuptools-58.1.0
Could you please help me in resolving this issue?
This occurs with an outdated pyOpenSSL version.
Edit: For anyone else who finds this. pyOpenSSL declares a min/max cryptography version to avoid incompatibilities like this, however it only started doing this in pyOpenSSL 22.1.0 and above. Upgrade to that version (or the latest, which would be a better choice: 23.0.0) and the issue will be (permanently) resolved.
Hi I'm having the same issue with cryptography==39.0.0 and pyOpenSSL==23.0.0. Downgrading to cryptography==38.0.4 and pyOpenSSL==22.1.0 didn't really help either.
Are you sure you're actually using cryptography 39.0.0 and pyopenssl 23.0.0?
The code to trigger this simply doesn't exist in pyopenssl, so I doubt that's what's happening. Perhaps try re-creating your virtualenv from scratch.
@alex yep my mistake! turns out I was just looking in the wrong place. thanks!
old version pyOpenssl using "cryptography>=35.0" ,but "cryptography==39.0.0" let openssl broken, and then pip broken too. maybe cryptography should keep compatibility as a cornerstone of pip?
cryptography is not a cornerstone of pip, but old versions of pip vendored an older version of urllib3 which automatically used pyopenssl if present in an environment. Upgrading pip or pyopenssl (or removing pyopenssl!) will fix that situation.
For aws-sam-cli users they have fixed their bug in 1.68.0. I'm going to leave this issue open for a bit longer so others can easily find the solution on the issue tracker (upgrade pyOpenSSL in your pins!), but ultimately this issue is not cryptography's bug.
Hi @reaperhulk The issue is fixed in the latest version of aws-sam-cli. I am not seeing any build failures now. This bug is good to close now. Thanks!