2017-09-22 6 views
0

なぜメソッドに変数を渡すことができないのか分かりません。変数 "モジュール" は実際にある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) 
+0

'device'の値は何ですか? 'default.Default.troubleshoot()'にはいくつの引数がありますか? – Barmar

+0

おそらく 'module.troubleshoot'でしょうか? – Barmar

答えて

0

私は、トラブルシューティングの方法でデフォルトのモジュールが1つのだけ引数を受け入れた...間違ったモジュールをチェックしていました。

私は別のモジュールlink_failureを見ていて、それが受け入れられたと思っていました。私の側に人間のエラーがありました。

+0

私はDefault.troubleshootメソッドをチェックしませんでした。それは1つの引数を取るだけです..ありがとうございました! – superloopnetworks

関連する問題