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’

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.