What to do if Insecure Platform Warning appears when running Python

2016/01/12 update

--Added about'requests [security]'. --Added about Software Collections.

Introduction

After installing a new Python or updating a package, do you ever think that the following warning appears when you run Python? (I was surprised to get a warning like this when I updated SoftLayer's Python package and tried to execute a command for the first time in a while). In this article, I'll show you how to avoid this Insecure Platform Warning warning.

# python test1.py
/usr/lib/python2.6/site-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
(Omitted below)

# sl vs list
/usr/lib/python2.6/site-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
(Omitted below)

Solution 1. Revert the requests package to 2.5.3 or earlier.

As you can see from the link below, it is implemented so that this warning message will appear in requests-2.6.0 or later. So a simple solution is to pip back requests to 2.5.3 by version. http://fossies.org/diffs/requests/2.5.3_vs_2.6.0/requests/packages/urllib3/util/ssl_.py-diff.html

# pip list | grep requests
requests (2.6.2)
# pip install requests==2.5.3
# pip list | grep requests
requests (2.5.3)

By the way, if you try to introduce a new package or upgrade, the requests that have been deferred may be updated at the same time (I hope you can downgrade later) If you defer it in requests 2.5.3. If you want to complete a new installation or package update in one shot, you can do as follows.

Example of introducing a new SoftLayer package


# pip install SoftLayer requests==2.5.3

Example of updating SoftLayer packages


# pip install --upgrade SoftLayer requests==2.5.3

Solution 2. Introduce requests [security].

http://stackoverflow.com/questions/29099404/ssl-insecureplatform-error-when-using-requests-package

requests[security]Introduction of


# yum install -y openssl-devel python-devel libffi-devel
# pip install 'requests[security]'

Solution 3. Change the Python version to 2.7.9 or later.

If you change the Python version to 2.7.9 or later, this warning will disappear. However, depending on the OS, Python is used at the system level, for example, CentOS and yum of RHEL are implemented in Python. Therefore, I personally think that changing the Python version at the system level is not very desirable.

In order to coexist with the new Software Package, CentOS and RHEL systems provide a component called Software Collections. You can use this to introduce Python 2.7 or Python 3.3. http://qiita.com/murachi1208/items/202bff84964188619f57 http://www.idcf.jp/blog/cloud/software-collections-for-centos-6/

In reality, I think it is better to use pyenv or virtualenv, which can switch versions as appropriate at the user level. Personally, it is very useful. Installing and compiling Python individually is quite a hassle, and I sometimes want to try different versions. How to use ... It seems that there are as many materials as you can if you google including Qiita, so I will omit it this time. https://github.com/yyuu/pyenv-virtualenv http://qiita.com/yuta_h3/items/2988c4d0811bf8c344c0 http://qiita.com/search?page=2&q=pyenv&sort=rel&utf8=%E2%9C%93

Reference link

https://urllib3.readthedocs.org/en/latest/security.html?highlight=insecureplatformwarning http://stackoverflow.com/questions/29134512/insecureplatformwarning-a-true-sslcontext-object-is-not-available-this-prevent

Recommended Posts

What to do if Insecure Platform Warning appears when running Python
What to do when a warning appears around Python integration in Neovim's CheckHealth
What to do if you get a "Wrong Python Platform" warning when using Python with the NetBeans IDE
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
[Memorandum] What to do when a warning appears after executing pip list
What to do if No Python documentation found for ... appears in pydoc
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
[Go 1.13] What to do when unexpected directory layout: appears
[openpyxl] What to do when IllegalCharacterError appears in pandas.DataFrame.to_excel
What to do if you get an error when installing python with pyenv
What to do when "cannot import name xxx" [Python]
What to do when [Errno 2] No such file or directory appears in Python
What to do when you can't bind CaboCha to Python
What to do if "export" keeps appearing on terminal when trying to put Python on macOS
What to do if you get an OpenSSL error when installing Python 2 with pyenv
[Python] What to do when No module named'pyproj.datadir' appears when Exe is done with PyInstaller
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
What to do if package installation fails when deploying to heroku
OSError: [Errno 40] What to do when Message too long appears
What to do when "Invalid HTTP_HOST header" appears in Django
What to do when Ubuntu crashes
What to do if yum breaks
What to do with PYTHON release?
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if Python doesn't work on Git for Windows
What to do if you can't install pyaudio with pip #Python
What to do if you get a minus zero in Python
What to do if python says "fatal error:'stdio.h' file not found"
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
What to do when the value type is ambiguous in Python?
What to do if grep: empty (sub) expression appears on Mac grep
What to do if there is a decimal in python json .dumps
What to do if you couldn't send an email to Yahoo with Python.
What to do if you can't use scikit grid search in Python
What to do when pyinstaller: error: argument --add-binary: invalid add_data_or_binary value: appears
[Docker] What to do when error Couldn't find the binary git appears
[Python] What to do when an error related to SSL authentication is returned
What to do if the server doesn't start with python manage.py runserver
What to do if an error occurs when importing numpy with VScode
What to do if you get an error when trying to load mnist
What to do if fprintd requires a password when registering your fingerprint
What to do if you get an error when installing Dlib (Ubuntu)
What to do when a warning message is displayed in pip list
[Python] What to do if you get a ModuleNotFoundError when importing pandas using Jupyter Notebook in Anaconda
What to do if pipreqs results in UnicodeDecodeError
[Python] What I did to do Unit Test
Note: What to do if pip install fails
What to do if mod_fcgid cannot resolve UnicodeEncodeError
What to do if rails s doesn't work
What to do if pip cannot be installed
What to do when PermissionError of tempfile.mkstemp occurs
What to do if atom autocomplete-python doesn't work
What I did when updating from Python 2.6 to 2.7
What to do to get google spreadsheet in python
What to do if Docker-sync suddenly stops working
What to do if "amazon-linux-extras" → "No module named amazon_linux_extras"
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
What to do if CERTIFICATE_VERIFY_FAILED occurs when nltk.download () is done on macOS pyhon
[python] What to do when an error occurs in send_keys of headless chrome