unsupported operand type (s) for +: 'NoneType' and 'NoneType'

2

I am trying to save elements that I parsed from a csv file in the database and at the time of splitting those elements I get an error unsupported operand type (s) for +: 'NoneType' and 'NoneType'and I do not know what do.

def Procesar(request, pk):  
    fichero = Cargar_Fichero.objects.get(id=pk)
    data = fichero.file
    da = data.name
    da = da[2:]
    try:
        path = MEDIA_ROOT + '/' + da
        ifile = open(path, "r")
        reader = csv.reader(ifile)
        print "Esto es lo que tengo%s" % reader
        list_rows = [row for row in reader]
        i = 0
        for row in list_rows:
            if 'Serial No.' in row:
                break
            i += 1
        valores_bajo_cabecera = list_rows[i + 1:]

        cont = 0
        for row in valores_bajo_cabecera:
            cont += 1
            # reportes= Reportes()
            split = row[0].split(',')
            sn = int(split[0])
            date = split[1]
            log = split[2].strip('="')
            event_co = split[3].strip('="')
            entyti_type = split[4].strip('="')
            entyti_valu = split[5].strip('="')
            action = split[6].strip('="')
            computer = split[7].strip('="')
            user = split[8].strip('="')
            user_role = split[9].strip('="')
            Reportes.objects.create(
            id_fichero=fichero,
                serial=sn,
                day=date,
                log_source=log,
                event_code=event_co,
                entyti_type=entyti_type,
                entyti_value=entyti_valu,
                action=action,
                computer=computer,
                user=user,
                user_role=user_role
            )

            w = action.split(' ')
            if 'change' in action:
                estado = w[-1]
            elif 'assigned' in action:
                estado = w[-1]
            else:
                estado ="%s %s" % (w[-2], w[-1])

            print(estado)


            try:

            # if Resultado.objects.get(nombre =user):
                resultado = Mostrar_Resultado.objects.get(nombre=user)#
                resultado.alarma_asignada += 1
                resultado.fecha=date

                if estado== 'Available':
                    resultado.disponible_Fr +=1
                elif estado=='as Fraudulent ':
                    resultado.fraude +=1
                elif estado=='Non Fraudulent':
                    resultado.no_fraude+=1

                else:
                    alarma=Alarmas.objects.get(nombre=user)
                    if estado=='was deleted':
                        alarma.eliminada +=1

                    elif estado =='to Investigation':
                        alarma.investigada +=1
                    else:
                        alarma.asignada +=1

                resultado.alm_inv= resultado.fraude+resultado.no_fraude+resultado.disponible_Fr
                resultado.bajo_inv_cierre=resultado.alarma_asignada-(resultado.fraude+resultado.no_fraude+resultado.disponible_Fr)
                resultado.por_ciento_fr=''
                resultado.uso_sistema=''
                resultado.save()
            except Mostrar_Resultado.DoesNotExist:
            # else:
                resultado = Mostrar_Resultado()

                resultado.nombre=user
                resultado.fecha=date
                resultado.alarma_asignada = 1

                if estado=='Available':
                    resultado.disponible_Fr =1

                elif estado=='as Fraudulent':
                    resultado.fraude=1

                elif estado=='Non Fraudulent':
                    resultado.no_fraude=1
                else:
                    alarma=Alarmas()
                    if estado=='was deleted':
                        alarma.eliminada =1

                    elif estado =='to Investigation':
                        alarma.investigada =1
                    else:
                        alarma.asignada =1
                resultado.alm_inv= resultado.fraude+resultado.no_fraude+resultado.disponible_Fr
                resultado.bajo_inv_cierre=resultado.alarma_asignada-(resultado.fraude+resultado.no_fraude+resultado.disponible_Fr)
                resultado.por_ciento_fr=''
                resultado.uso_sistema=''
                resultado.save() 
    
asked by Eric 25.04.2016 в 20:01
source

1 answer

2

In Python, NoneType is the data type for the None object, which is an object that exactly indicates the absence of value. For this reason, you can not use it with another object with the + operator (the operation is not defined for this type of data).

But, why is this happening to me?
In your lines:

resultado.alm_inv= resultado.fraude+resultado.no_fraude+resultado.disponible_Fr
resultado.bajo_inv_cierre=resultado.alarma_asignada-(resultado.fraude+resultado.no_fraude+resultado.disponible_Fr)

Some of the operands may not be assigned because in the if you have above, do not contemplate an initial value for them (probably must be 0).

    
answered by 25.04.2016 / 23:11
source