[Solved-5 Solutions] SSL InsecurePlatform error when using Requests package
Error Description:
- When making https requests with Requests we get an
InsecurePlatform
exception. - The error mentions
urllib3,
but we don't have that installed
/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.
click below button to copy the code. By - python tutorial - team
Solution 1:
- Use the somewhat hidden security feature:
pip install 'requests[security]'
orpip install pyOpenSSL ndg-httpsclient pyasn1
- Both commands install following extra packages:
- pyOpenSSL
- cryptography
- idna
- Please note that this is not required for python-2.7.9+ .
- If
pip install
fails with errors, check whether you have required development packages forlibffi, libssl
andpython
installed in your system using distribution's package manager: - Debian/Ubuntu - python-dev libffi-dev libssl-dev packages.
- Fedora - openssl-devel python-devel libffi-devel packages.
- In case you cannot install some of the required development packages, there's also an option to disable that warning:
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
click below button to copy the code. By - python tutorial - team
Solution 2:
- Requests 2.6 introduced this warning for users of python prior to 2.7.9 with only stock SSL modules available.
- Assuming you can't upgrade to a newer version of python, this will install more up-to-date python SSL libraries:
pip install --upgrade ndg-httpsclient
click below button to copy the code. By - python tutorial - team
- pip install --upgrade ndg-httpsclient
apt-get install python-dev libffi-dev libssl-dev
click below button to copy the code. By - python tutorial - team
Solution 3:
- If you know what you are doing and would like to disable this and other warnings
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
click below button to copy the code. By - python tutorial - team
Solution 4:
- The following should also work:
import logging
import requests
# turn down requests log verbosity
logging.getLogger('requests').setLevel(logging.CRITICAL)
click below button to copy the code. By - python tutorial - team
Solution 5:
- If you are not able to upgrade your Python version to 2.7.9, and want to suppress warnings,
- you can downgrade your 'requests' version to 2.5.3:
sudo pip install requests==2.5.3