Solving Python Error – A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately

Solving Python Error – A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately is an error which occurs in Python because pyOpenSSL is not available.

In this article we are going to explain why the error is popping up and show you how to solve the error and get rid of it for good.

Explaining Python Error – A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately

This error happens a lot because of the lack of an ssl certificate, bellow is the message of the error.

The error message from your part should look like something like this.

                                                                       #
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:79: 
InsecurePlatformWarning: A true SSLContext object is not available. 
This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. 
For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
                                                                       #

Bellow is a number of tested solutions that I have tried and worked for me.

Solution 1 : Upgrade python

Another solution is to try to upgrade python to the newest version, I am not going to show you how to do that because that is out of the scope of this article.

If that did not do the trick, there are other fixes which you can try, continue reading.

Solution 2 : use pyOpenSSL

The easiest solution to try installing pyOpenSSL.

You can do that by running the command bellow.

                                                                       #
pip install pyOpenSSL
                                                                       #

Sometimes you should install the dependencies too, do that by running the command bellow instead

                                                                       #
pip install pyopenssl ndg-httpsclient pyasn1
                                                                       #

For ubuntu users, you should run the command bellow.

                                                                       #
apt-get install libffi-dev libssl-dev
                                                                       #

You can also try running the command bellow.

                                                                       #
pip install requests[security]
                                                                       #

If that did not do the trick, there is another fixe which you can try, continue reading.

Solution 3 : Downgrade requests

This is the final solution, it got a lot of people out of trouble and solved the problem perfectly for them you can try it and see if the error is gone.

You can downgrade using the command bellow.

                                                                       #
pip install requests==2.5.2
                                                                       #

The error above was hard to deal with, I spent hours looking for a proper solution or set of solutions.

Summing-up

That is it guys, this is the end of this article aka guide, I hope you found it useful in solving your problem, make sure to support our work on Kofi, you do not have to but hey you can donate to the team.

The error was a matter of syntax, it usually happens when you are just starting but mistakes always happen even to experienced developers, thank you for reading and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/