How to Fix AttributeError: ‘module’ object has no attribute ‘SSL_ST_INIT’

AttributeError - 'module' object has no attribute 'SSL_ST_INIT'

To fix the AttributeError: ‘module’ object has no attribute ‘SSL_ST_INIT’ error, “update the pyopenssl package.”

AttributeError: ‘module’ object has no attribute ‘SSL_ST_INIT’ error occurs in Python when you are “using an older version of OpenSSL library.” 

The main reason for the error suggests that the version of the OpenSSL library you are using doesn’t recognize the attribute SSL_ST_INIT.

How to fix it?

If you use an older version of OpenSSL, you should “install/upgrade the pyOpenSSL package using pip.”

pip install --upgrade pyOpenSSL

You can check the installed versions of OpenSSL and pyOpenSSL using:

import OpenSSL

print(OpenSSL.__version__)
print(OpenSSL.SSL.SSLeay_version(OpenSSL.SSL.SSLEAY_VERSION))

Output

23.2.0
b'OpenSSL 3.0.7 1 Nov 2022'

You can see that I am using a newer version of pyopenssl on my system.

An alternate way you can use is to upgrade pyopenssl with easy_install.

sudo python -m easy_install --upgrade pyopenssl

If the error is still not fixed, then you can try to uninstall the pyopenssl package and install it again.

pip uninstall pyopenssl

pip install pyopenssl

This will surely fix the error and won’t interfere with existing packages.

Related posts

AttributeError: ‘module’ object has no attribute ‘SSLContext’

AttributeError: module ‘OpenSSL.SSL’ has no attribute ‘SSLv3_METHOD’

AttributeError: module ‘lib’ has no attribute ‘ssl_ctx_set_ecdh_auto’

AttributeError: module ‘lib’ has no attribute ‘OpenSSL_add_all_algorithms’

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.