Attributeerror: 'Nonetype' Object has no attribute '_product'

Asked

Viewed 774 times

0

I’m trying to do a project with Python and Docker, but I’m having some programming problems. I have 2 error files that are Provisionops.py and Dockerops.py.

Follow the Provisionops.py

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    #ProvisionOps.py

    from Service import Service as ServiceClass
    from ServiceDao import ServiceDao
    from DockerOps import DockerOps

  class ProvisionOps:

  _id = ""

def __init__(self,id):
    self._id = id

def InstallService(self):
    service = ServiceClass()
    service._id = self._id

    sd = ServiceDao(service)
    service = sd.get()

    print "Sera instalado o Produto ( %s ) para o Client ( %s )"%(service._product._name,service._client._name)
    docker = DockerOps()
    res = docker.createContainer(service._id,service._product._image)

def RemoveService():
    pass

And the Dockerops.py

   #!/usr/bin/python
   # -*- coding: UTF-8 -*-
  #DockerOps.py

  from SshOps import SshOps

  class DockerOps:

def __init__(self):
    pass

def createContainer(self,id,image):
    command = "docker run -d -ti --name %s %s"%("%s_%s"%(image,id),'debian')
    ssh = SshOps()
    res = ssh.runCommand(command)
    if res['status'] == 1:
        print res['message']
    else:
        command = "docker exec %s apt-get update %s"%(id,image)
        res = ssh.runCommand(command)

def removeContainer(self,id,image):
    command = "docker stop %s"%("%s_%s"%(image,id))
    ssh = SshOps()
    res = ssh.runCommand(command)
    if res['status'] == 1:
        print res['message']

    command = "docker rm %s"%("%s_%s"%(image,id))
    res = ssh.runCommand(command)
    if res['status'] == 1:
        print res['message']
    else:
        print res['message']

And when I run the main file gives this error

  python DevOps.py 
  Existem 11 servicos na fila 
  Instalando servico:  3
  Sera instalado o Produto ( Backup ) para o Client ( XPTO2 )
  /usr/lib/python2.7/dist-packages/Crypto/Cipher/blockalgo.py:141:       FutureWarning: CTR mode needs counter parameter, not IV
    self._cipher = factory.new(key, *args, **kwargs)
        docker: Error response from daemon: Conflict. The container name       "/backup_3" is already in use by container "36fdfa851993eb5f8dba38b3b3edbe423a4a46aa821ffd4de4c21143a0d78d56". You have       to remove (or rename) that container to be able to reuse that name.
  See 'docker run --help'.

  Instalando servico:  5
  Traceback (most recent call last):
    File "DevOps.py", line 27, in <module>
      Start()
    File "DevOps.py", line 24, in Start
      res = prov.InstallService()
    File "/home/vitor/Documentos/Udemy/Python/Códigos/0 - Projeto       Devops/ProvisionOps.py", line 23, in InstallService
      print "Sera instalado o Produto ( %s ) para o Client ( %s       )"%(service._product._name,service._client._name)
  AttributeError: 'NoneType' object has no attribute '_product'

Follow the file Servicedao.py

     #!/usr/bin/python
     # -*- coding: UTF-8 -*-
      #ServiceDao.py

   from Service import Service as ServiceClass
   from Client import Client as ClientClass
   from Product import Product as ProductClass
   from Model import Service as ServiceTable,Client,Product, session

   class ServiceDao:

   def __init__(self,service=""):
    self._service = service

   def get(self):
    try:
        service = session.query(ServiceTable,Client,Product).join(Client,Product).filter(ServiceTable.id==self._service._id).first()

        if service is None:
            return None
        else:
            c = ClientClass(service.Client.name,service.Client.cpf,service.Client.segment)
            c._id = service.Client.id

            p = ProductClass(service.Product.name,service.Product.description,service.Product.image)
            p._id = service.Product.id

            s = ServiceClass(service.Service.request_date,service.Service.cancel_date)
            s._id = service.Service.id
            s._client = c
            s._product = p

            return s
    except Exception as e:
        print "Erro: ",e

The error is in this '_product' but I have tried to remove etc but do not know how to fix this problem.

Would anyone know how to solve this problem?

Hugs

  • 1

    What would be the method sd.get()? Apparently he is returning None. As for the first mistake, it seems to be name conflict.

  • @Andersoncarloswoss d.get() is Servicedao.py file error, I will post above.

  • 1

    This is probably where your mistake is: service = session.query(...), is returning None, in the method get class ServiceDao.

  • @Andersoncarloswoss I’ll see where I can fix, but the funny thing I get to install some Ockers there when it comes to this item it hangs, because it will be?

No answers

Browser other questions tagged

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