2013-02-23 9 views
0

첫 번째 패스의 모든 것이 잘 작동 더 __call__ 방법이 없다,하지만 두 번째 실행은 내가 AttributeError를 얻을 : 예를 더는 __ addinfourl의 call__ 방법은, 내가 잘못AttributeError는 : addinfourl 인스턴스

첫 번째 패스이 무엇인지 알 수있다 진정한 상태 : 확인

두 번째 전달 파일 mainstatus.bite() 파일의 "D : \ python \ New Status \ status.py"파일의 "D : \ python \ New Status \ status.py" 109, 물음에 s = file ("cc.beat") AttributeError : addinfourl 인스턴스에 호출 메서드가 없습니다.

기본적으로 상태를 확인하는 데 사용합니다 와 서버의 두 번하는 urllib2.urlopen() 호출의 결과를 저장하기 위해 전역 변수 file를 사용하는

failure = True 
    servestatus = False 


    def log(): 
     a=open ("Status.failures","a") 
     now = datetime.now() 
     tiempo = str (now) +" - Error\n" 
     a.write(tiempo) 
     a.close() 

    class mainstatus(object): 

     @staticmethod 
     def xmlstatus(): 
      try:   
       file = urllib2.urlopen('http://192.168.1.110:9900/admin/xmlstatus?user=&password=') 
       data = file.read() 
       file.close() 
       dom = parseString(data) 
       xmlTag = dom.getElementsByTagName('Status')[0].toxml() 
       xmlData=xmlTag.replace('<Status>','').replace('</Status>','') 
       if xmlTag == "<Status>OK</Status>": 
        stat = True 
      except: 
       stat= False 
      return stat 

     @staticmethod 
     def hola(): 
      x = "test" 
      return x 

     @staticmethod 
     def internet(url): 
      try: 
       response=urllib2.urlopen(url,timeout=1) 
       return True 
      except urllib2.URLError as err: pass 
      return False 

     @staticmethod 
     def heartbeat(): 
      a=open ("heart.beat","w") 
      now = datetime.now() 
      tiempo = str (now.minute) 
      a.write(tiempo) 
      a.close() 

     @staticmethod 
     def push(mensaje): 
      #Miguel 
      conn = httplib.HTTPSConnection("api.pushover.net:443") 
      conn.request("POST", "/1/messages.json", 
       urllib.urlencode({ 
       "token": "", 
       "user": "", 
       "message": mensaje, 
       }), { "Content-type": "application/x-www-form-urlencoded" }) 
      conn.getresponse() 
      #Gerswin 
      conn = httplib.HTTPSConnection("api.pushover.net:443") 
      conn.request("POST", "/1/messages.json", 
       urllib.urlencode({ 
       "token": "", 
       "user": "", 
       "message": mensaje, 
       }), { "Content-type": "application/x-www-form-urlencoded" }) 
      conn.getresponse() 

     @staticmethod 
     def colam(): 
      cola = 0 
      for root, dirs, files in os.walk("\\\\Server0\\smsdata\\Q"): 
        for file in files:  
          if file.endswith('.req'): 
            cola += 1 
     @staticmethod 
     def wol(): 
      HOST = "192.168.1.1" 
      user = "root" 
      password = "16745665" 
      tn = telnetlib.Telnet(HOST) 
      tn.read_until("login: ") 
      tn.write(user + "\n") 
      if password: 
       tn.read_until("Password: ") 
       tn.write(password + "\n") 
      tn.write("/usr/sbin/wol -i 192.168.1.255 -p 7 00:11:25:36:08:FE\n") 
      tn.write("exit\n") 
      tn.read_all() 

     @staticmethod 
     def bite(): 
      now = datetime.now() 
      tiempo = (now.minute) 
      s = file("cc.beat") 
      status = int(s.readline()) 
      s.close() 
      vivo = tiempo - status  
      if (vivo > 0): 
       return False 
      else: 
       return True 

    count = 5 
    print "Server Status Check: Runing..." 

    while (count < 9): 

     time.sleep(2) 
     print mainstatus.bite() 
     pulso = True 
     if pulso == False: 
      #os.startfile('check.exe') 
      print "activa" 
     else: 
      pass 
     status = mainstatus.internet("http://192.168.1.110:9900") 
     mainstatus.heartbeat() 
     if status == True: 
      if mainstatus.xmlstatus() == True: 
       print '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bStatus:OK', 

       if failure == True: 
        accion = os.system('net stop "NowSMS"') 
        file = urllib2.urlopen('http://sql.gerswin.com/status.php?status=OK') 
        data = file.read() 
        file.close() 
        failure = False 

       if mainstatus.colam() >= 20 and servestatus == False: 
        accion = os.system('net start "NowSMS"') 
        mainstatus.push("Server Overload, Server 2 Running") 
        servestatus = True 
       else: 
        if mainstatus.colam() < 20 and servestatus == True: 
         mainstatus.push("Stoping Server 2") 
         accion = os.system('net stop "NowSMS"') 
         servestatus = False 
         file = urllib2.urlopen('http://sql.gerswin.com/status.php?status=OK') 
         data = file.read() 
         file.close() 

      else: 
       print '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bStatus: Modem Failure', 
       mainstatus.wol()   
       if servestatus == False: 
        accion = os.system('net start "NowSMS"') 
        mainstatus.push("Modem Failure, Server 2 Running") 
        log() 
        file = urllib2.urlopen('http://sql.gerswin.com/status.php?status=2') 
        data = file.read() 
        file.close() 
        servestatus = True 

     else: 
      print "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bStatus: Fallo Server", 
      mainstatus.wol() 
      if servestatus == False:   
       accion = os.system('net start "NowSMS"') 
       file = urllib2.urlopen('http://192.168.1.110:9900?ok=no') 
       data = file.read() 
       file.close() 
       log() 
       mainstatus.push("Server Failure, Server 2 Running") 
       servestatus = True 
+0

질문 제목과 질문 내용에는 다른 오류 메시지가 있습니다. 당신은 * full * traceback을 포함시켜 주시겠습니까? 들여 쓰기 된 블록을 사용하여 코드와 마찬가지로 형식을 지정하십시오. –

+0

첫 번째 패스 진정한 상태 : OK 두 번째 패스 파일 "D : \ 파이썬 새로운 상태 \의 status.py \" 인쇄 mainstatus.bite에서, 라인 (124),() 파일 "D : \ 파이썬 \ 새로운 상태 \ status.py ", 줄 109, 물음표 s = file ("cc.beat ") AttributeError : addinfourl 인스턴스에 __call__ 메서드가 없습니다. –

+1

질문을 추가해야 편집 할 수 있습니다. –

답변

2

다른 프로세스가 활성화되어 있는지 확인합니다.

>>> import urllib2 
>>> file('/dev/random') 
<open file '/dev/random', mode 'r' at 0x10c8ee660> 
>>> file = urllib2.urlopen('http://stackoverflow.com') 
>>> file('/dev/random') 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
AttributeError: addinfourl instance has no __call__ method 

은하지 말라 :하지만 당신은 또한 내장 file() type로 사용하기 위해 기대하고있다. 변수 이름이 이고 인 내장 함수를 섀도 잉하지 말고 file()을 사용하지 마십시오. 대신 open() function을 사용하십시오.

>>> open('/dev/random') 
<open file '/dev/random', mode 'r' at 0x10c8ee6f0> 
>>> response = urllib2.urlopen('http://stackoverflow.com') 
관련 문제