"session_start" event is not firing.

46 views
Skip to first unread message

Saurav Gupta

unread,
Mar 18, 2018, 8:07:33 AM3/18/18
to SleekXMPP Discussion
Hi,
I am new to XMPP having some knowledge of Python. I am trying to send and receive XMPP messages. I have configured "ejabberd" server on ubuntu. With the below python code:

import sys
import logging
import getpass
from optparse import OptionParser

import sleekxmpp

if sys.version_info < (3, 0):
    reload(sys)
    sys.setdefaultencoding('utf8')
else:
    raw_input = input


class SendMsgBot(sleekxmpp.ClientXMPP):

    """
    A basic SleekXMPP bot that will log in, send a message,
    and then log out.
    """

    def __init__(self, jid, password, recipient, message):
        sleekxmpp.ClientXMPP.__init__(self, jid, password)

        self.recipient = recipient
        self.msg = message
        
        self.add_event_handler("session_start", self.start)

    def start(self, event):
        """
        Process the session_start event.

        Typical actions for the session_start event are
        requesting the roster and broadcasting an initial
        presence stanza.

        Arguments:
            event -- An empty dictionary. The session_start
                     event does not provide any additional
                     data.
        """
        self.send_presence()
        self.get_roster();print "jdfkjdfh......"

        self.send_message(mto=self.recipient,
                          mbody=self.msg,
                          mtype='chat')

        self.disconnect(wait=True)


if __name__ == '__main__':
    
    optp = OptionParser()

    
    optp.add_option('-q', '--quiet', help='set logging to ERROR',
                    action='store_const', dest='loglevel',
                    const=logging.ERROR, default=logging.INFO)
    optp.add_option('-d', '--debug', help='set logging to DEBUG',
                    action='store_const', dest='loglevel',
                    const=logging.DEBUG, default=logging.INFO)
    optp.add_option('-v', '--verbose', help='set logging to COMM',
                    action='store_const', dest='loglevel',
                    const=5, default=logging.INFO)

    # JID and password options.
    optp.add_option("-j", "--jid", dest="jid",
                    help="JID to use")
    optp.add_option("-p", "--password", dest="password",
                    help="password to use")
    optp.add_option("-t", "--to", dest="to",
                    help="JID to send the message to")
    optp.add_option("-m", "--message", dest="message",
                    help="message to send")

    opts, args = optp.parse_args()

    logging.basicConfig(level=opts.loglevel,
                        format='%(levelname)-8s %(message)s')

    if opts.jid is None:
        opts.jid = raw_input("Username: ")
    if opts.password is None:
        opts.password = getpass.getpass("Password: ")
    if opts.to is None:
        opts.to = raw_input("Send To: ")
    if opts.message is None:
        opts.message = raw_input("Message: ")

    xmpp = SendMsgBot(opts.jid, opts.password, opts.to, opts.message)
    xmpp.register_plugin('xep_0030') # Service Discovery
    xmpp.register_plugin('xep_0199') # XMPP Ping ;

    if xmpp.connect(('192.168.2.130', 5280)):    
        
xmpp.process(block=True)
print("Done")
    else:
        print("Unable to connect.") 

I am getting 
        INFO     Waiting for </stream:stream> from server
        ERROR    Error reading from XML stream.

As per a little debugging I believe "start(self, event)" is not executing. 

Thanks in advance.

lexx...@gmail.com

unread,
Mar 20, 2018, 4:22:05 AM3/20/18
to SleekXMPP Discussion

 optp.add_option('-v', '--verbose', help='set logging to COMM',
                    action='store_const', dest='loglevel',
                    const=5, default=logging.INFO)


-v - verbose and you will see that it is started if your credentials are good - I mean JID and password
воскресенье, 18 марта 2018 г., 14:07:33 UTC+2 пользователь Saurav Gupta написал:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages