8

I get this warning when building my Docker image:

/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.

Several sources (like InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately) say that pip install pyopenssl ndg-httpsclient pyasn1 will fix this issue. But I get the warning as soon as pip attemps to install pyopenssl.

Here's my Dockerfile:

FROM ubuntu:14.04

# Install packages
RUN apt-get update && apt-get install -y \
    git \
    libmysqlclient-dev \
    mysql-server \
    nginx \
    python-dev \
    python-mysqldb \
    python-setuptools \
    supervisor \
    vim
RUN easy_install pip

# Handle urllib3 InsecurePlatformWarning
RUN apt-get install -y libffi-dev libssl-dev
RUN pip install pyopenssl ndg-httpsclient pyasn1

# ...more
Joe Mornin
  • 8,766
  • 18
  • 57
  • 82
  • try using the --upgrade flag like: `RUN pip install --upgrade pyopenssl ndg-httpsclient pyasn1` – dopstar Sep 26 '15 at 01:02
  • No luck (which makes sense, since there are no existing packages for pip to upgrade when the Docker image is built--unless I'm misunderstanding `pip install --upgrade`). – Joe Mornin Sep 26 '15 at 01:17
  • try to add `libpython2.7-dev` in `RUN apt-get install -y libffi-dev libssl-dev`. also it's better to `pip install requests[security]` instead of `pip install pyopenssl` – ahmed Sep 26 '15 at 18:59
  • Thanks, but still no luck. – Joe Mornin Sep 27 '15 at 03:32
  • You can try installing urllib3 and related packages directly from the Ubuntu distro, I think it's python-urllib3. – shazow Sep 27 '15 at 17:02
  • It seems that these warnings are expected when running pip: https://github.com/pypa/pip/issues/2681 but as you are installing `pyopenssl ndg-httpsclient pyasn1` you shouldn't get warnings when using python requests. – Céline Aussourd Oct 08 '15 at 10:23

1 Answers1

3

It seems that this warning is expected when running pip: http://github.com/pypa/pip/issues/2681 but as you are installing pyopenssl ndg-httpsclient pyasn1, you won't get warnings when using python requests.

For example, if I build this Dockerfile:

FROM ubuntu:14.04

# Install packages
RUN apt-get update && apt-get install -y \
    git \
    libmysqlclient-dev \
    mysql-server \
    nginx \
    python-dev \
    python-mysqldb \
    python-setuptools \
    supervisor \
    vim
RUN easy_install pip
RUN pip install requests

and then run this inside the container:

root@b2759f79f947:/# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import requests

>>> url = "https://www.digicert.com/"

>>> r = requests.get(url)

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:100: 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

As you can see, I get the warning. But if I add these lines in the Dockerfile:

RUN apt-get install -y libffi-dev libssl-dev
RUN pip install pyopenssl ndg-httpsclient pyasn1

and run the same python commands, I don't get the warning anymore.

If you really don't want the warning when installing pyopenssl, you can set the environment variable: PYTHONWARNINGS="ignore:a true SSLContext object" as suggested here: https://github.com/pypa/pip/pull/3109

Your Dockerfile would then look like this:

FROM ubuntu:14.04

# Install packages
RUN apt-get update && apt-get install -y \
    git \
    libmysqlclient-dev \
    mysql-server \
    nginx \
    python-dev \
    python-mysqldb \
    python-setuptools \
    supervisor \
    vim
RUN easy_install pip

# Handle urllib3 InsecurePlatformWarning
RUN apt-get install -y libffi-dev libssl-dev
ENV PYTHONWARNINGS="ignore:a true SSLContext object"
RUN pip install pyopenssl ndg-httpsclient pyasn1

Another solution would be to upgrade python to 2.7.9

Céline Aussourd
  • 10,214
  • 4
  • 32
  • 36