module 'Docker' has no attribute 'Client'

Asked

Viewed 84 times

-1

I’m using the Docker-py in version 3.7 of Python and when I try to execute the function that uses it an Attributeerror is returned

My code:

from django.shortcuts import render
from django.http import HttpResponse
import docker

    # Create your views here.
    def index(Request):

        client = docker.Client(base_url='unix://var/run/docker.sock')
        events = objdocker.events()
        for event in events:
            return HttpResponse(event)
            # and cancel from another thread
            events.close()

Error received:

Attributeerror at /Docker/ module 'Docker' has no attribute 'Client'

ps. I have tried using version 2.7 of Python thinking that the Docker api would better accept Docker, but it is not compatible.

  • And what documentation did you use as a basis? current, in fact, there is no class called Client and yes there is a call DockerClient.

  • I used this link https://docker-py.readthedocs.io/en/stable/client.html but I saw on some forums that Docker. Client is more current, however in both cases the error persists.

1 answer

0


Most likely there is that you have in your project some file called docker.py - and command and import loads this file in place of the library docker installed in the Python environment.

Just rename the file that has this name in your project to anything else, and this error should disappear.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.