Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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
about 4 years ago · Santiago Trujillo Report

0

On Ubuntu/Debian, there is a bug related to package upgrade (bug #893520) at the moment, where the __init__.py file is not generated.

Check if the following file exists: /usr/lib/python2.7/dist-packages/backports/__init__.py

If it does not exist and the package python-backports.ssl-match-hostname is installed, then run the following command to generate the missing file:

sudo pycompile -p python-backports.ssl-match-hostname
about 4 years ago · Santiago Trujillo Report

0

I had backports.ssl-match-hostname installed locally, which was preventing it from being installed at the system level. I solved it by

sudo pip uninstall backports.ssl-match-hostname

followed by

sudo pip install --upgrade docker
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!