Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named ssl_match_hostname when importing the docker SDK for Python

Tags:

In order to use the Docker SDK for Python, I'm trying to import docker in a Python script, but it's resulting in an ImportError with the following traceback:

Traceback (most recent call last):   File "/home/kurt/dev/clones8/ipercron-compose/furion/iclib/tests/test_utils/docker_utils.py", line 1, in <module>     import docker   File "/home/kurt/.local/lib/python2.7/site-packages/docker/__init__.py", line 6, in <module>     from .client import Client, AutoVersionClient, from_env # flake8: noqa   File "/home/kurt/.local/lib/python2.7/site-packages/docker/client.py", line 11, in <module>     from . import api   File "/home/kurt/.local/lib/python2.7/site-packages/docker/api/__init__.py", line 2, in <module>     from .build import BuildApiMixin   File "/home/kurt/.local/lib/python2.7/site-packages/docker/api/build.py", line 9, in <module>     from .. import utils   File "/home/kurt/.local/lib/python2.7/site-packages/docker/utils/__init__.py", line 2, in <module>     from .utils import (   File "/home/kurt/.local/lib/python2.7/site-packages/docker/utils/utils.py", line 19, in <module>     from .. import tls   File "/home/kurt/.local/lib/python2.7/site-packages/docker/tls.py", line 5, in <module>     from .ssladapter import ssladapter   File "/home/kurt/.local/lib/python2.7/site-packages/docker/ssladapter/__init__.py", line 1, in <module>     from .ssladapter import SSLAdapter # flake8: noqa   File "/home/kurt/.local/lib/python2.7/site-packages/docker/ssladapter/ssladapter.py", line 21, in <module>     from backports.ssl_match_hostname import match_hostname ImportError: No module named ssl_match_hostname [Finished in 0.2s with exit code 1] [shell_cmd: python -u "/home/kurt/dev/clones8/ipercron-compose/furion/iclib/tests/test_utils/docker_utils.py"] [dir: /home/kurt/dev/clones8/ipercron-compose/furion/iclib/tests/test_utils] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin] 

The strange thing is that the import does work in other places, for example in an iPython prompt:

Python 2.7.12 (default, Nov 19 2016, 06:48:10)  Type "copyright", "credits" or "license" for more information.  IPython 2.4.1 -- An enhanced Interactive Python. ?         -> Introduction and overview of IPython's features. %quickref -> Quick reference. help      -> Python's own help system. object?   -> Details about 'object', use 'object??' for extra details.  In [1]: import docker  In [2]:  

Why is the import not working in the first case?

like image 898
Kurt Peek Avatar asked Mar 09 '17 12:03

Kurt Peek


1 Answers

Upgrading docker didn't solve the problem for me. Instead, I had to install the backports as Ubuntu package (and uninstall from pip):

sudo pip uninstall backports.ssl-match-hostname sudo apt-get install python-backports.ssl-match-hostname 
like image 130
CGFoX Avatar answered Sep 19 '22 16:09

CGFoX