fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

sleekxmpp.ClientXMPP object has no attribute '_XMLStream__event_handlers' #124

Closed alexandr999 closed 12 years ago

alexandr999 commented 12 years ago

I have written a mini-example for myself.

/usr/bin/env python3

import logging import time import sleekxmpp

class MyTest (sleekxmpp.ClientXMPP):

def __init__ (self, jid, password):
    self.add_event_handler ("session_start", self.handleStart)
    self.add_event_handler ("message", self.handleIncomingMessage)

def run (self):
    self.connect ()
    self.process (threaded=False)
    self.get_roster ()
    self.sendPresence ()
    self.status = 1

def handleStart (self, event):
    print ("Session start")

def handleIncomingMessage (self, message):
    print (message["from"], message["body"])

def main (): import sys jid = raw_input ("Jid: ") password = raw_input ("Password: ") test = MyTest (jid, password) test.run () while test.status: time.sleep (1)

if name == "main": main ()

I add hadler for presence_probe. Then I remove it. Now when I run this program I get error:

File "./myclient.py", line 39, in main () File "./myclient.py", line 33, in main client = MyClient (jid, password) File "./myclient.py", line 10, in init self.add_event_handler ("session_start", self.handleXMPPConnected) File "/usr/local/lib/python3.2/site-packages/sleekxmpp/xmlstream/xmlstream.py", line 878, in add_event_handler if not name in self.event_handlers: AttributeError: 'MyClient' object has no attribute '_XMLStreamevent_handlers'

legastero commented 12 years ago

And you are using the del_event_handler() method to do the removing, correct?

alexandr999 commented 12 years ago

no, i just del this handler from my file

legastero commented 12 years ago

Oh, I see. You need to call the constructor for the parent class in your init method.

def __init__(self, jid, password):
    super(MyClient, self).__init__(jid, password)
alexandr999 commented 12 years ago

thanks