なぜメソッドに変数を渡すことができないのか分かりません。変数 "モジュール" は実際にあるlinkFailureのオブジェクトを作成している:ここではTypeError:ちょうど1つの引数をとります(6が与えられます)
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
私がそれを実行すると、ここにトレースバックがあります:
なぜ私はalre adyはメソッドに自身を含めて6を定義しましたか?
<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)
'device'の値は何ですか? 'default.Default.troubleshoot()'にはいくつの引数がありますか? – Barmar
おそらく 'module.troubleshoot'でしょうか? – Barmar