TypeError:只取1个参数(给定6个)

时间:2017-09-22 22:40:11

标签: python arguments traceback

无法弄清楚为什么它不允许我将变量传递给方法。变量"模块"实际上是在创建LinkFailure的对象:

from lib.remediation.link_failure import LinkFailure
from mapping import get_remediation

def remediation(dstamp,tstamp,device,error_code,error_message,ntw_device):
    module = get_remediation(error_code)
    device = module(*ntw_device)
    device.troubleshoot(dstamp,tstamp,device,error_code,error_message)

这是我获取LinkFailure的映射文件:

######################## FUNCTIONS ##############################
from lib.remediation import link_failure 
from lib.remediation import default 

ERROR_CODES_TO_REMEDIATIONS = {
        'LINEPROTO-5-UPDOWN': link_failure.LinkFailure
}

DEFAULT_REMEDIATION = {
        'default': default.Default
}

def get_remediation(error_code):

        if error_code in ERROR_CODES_TO_REMEDIATIONS:
                module = ERROR_CODES_TO_REMEDIATIONS[error_code]
        else:
                module = DEFAULT_REMEDIATION['default']

        return module

这是我的班级文件:

from initialize import Initialize

class LinkFailure(Initialize):

    def troubleshoot(self,dstamp,tstamp,device,error_code,error_message):
        print 'LINK FAILURE'
        print dstamp,device

当我运行它时,这里是追溯:

为什么在我已经定义了6个方法时它只允许1个参数?

<Thread(Thread-1, started 140335459219200)>
Sep 22 18:26:49 x.x.x.x LINK-5-CHANGED Interface GigabitEthernet1/0/12, changed state to administratively down
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/root/staging/superloopAR/parser.py", line 23, in parser
    event(dstamp,tstamp,device,error_code,error_message,ntw_device)
  File "/root/staging/superloopAR/event.py", line 9, in event
    remediation(e.datestamp,e.timestamp,e.device,e.error_code,e.error_message,ntw_device)
  File "/root/staging/superloopAR/remediation.py", line 11, in remediation
    device.troubleshoot(dstamp,tstamp,device,error_code,error_message)
TypeError: troubleshoot() takes exactly 1 argument (6 given)

1 个答案:

答案 0 :(得分:0)

我正在检查错误的模块..带有故障排除方法的默认模块只接受1个参数。

我正在查看另一个模块,link_failure,并认为它接受了6.人为错误在我身边。