XMPPPY won't connect to Openfire

Hi, I’m trying to simply connect XMPPPY to Openfire, send a message, then close. The problem is that I keep getting

(Python 2.6)

import xmpp

pwd = “password”

jid=xmpp.protocol.JID(“testuser@localhost”)

cl=xmpp.Client(jid.getDomain()) #which translates to ‘localhost’

cl.connect()

DEBUG: socket start Plugging <xmpp.transports.TCPsocket instance at 0x190ea1b8> into <xmpp.client.Client instance at 0x190e5320>

DEBUG: socket start Successfully connected to remote host (‘localhost’, 5222)

DEBUG: dispatcher start Plugging <xmpp.dispatcher.Dispatcher instance at 0x190ea2d8> into <xmpp.client.Client instance at 0x190e5320>

cl.auth(jid.getNode(),pwd) #translates to ‘testuser’ / ‘password’

DEBUG: sasl error Failed SASL authentification:

DEBUG: sasl stop Plugging <xmpp.auth.SASL instance at 0x190f0320> out of <xmpp.client.Client instance at 0x190e5320>.

I’m 100% sure that the username and password are correct as I’ve tried many times and can connect via Spark.

Is there a setting somewhere that I’m missing / has anyone has success with this?

Did you ever find a solution for this?

Hi Mike,

I couldn’t get xmpppy to work, but found it’s predecessor, jabberpy, which worked fine (it’s not developed anymore though).

http://jabberpy.sourceforge.net/

Hope this helps.

Thanks Joe. Do you have any working sample code?

First off, don’t use the setup.py; it doens’t work. Instead, copy the contents of the jabber folder (3 x .py) into your Python site-package folder.

Then:

import jabber

cx = jabber.Client(HOSTNAME OF SERVER)

cx.connect()

cx.auth(USERNAME, PASSWORD, NICENAME)

cx.sendInitPresence() #Shows the world you’re online

That should get you connected. The examples are quite nice to start on.**
**

This is pretty much the point I get to with all xmpp python libs:

import jabber

import xmpp

cx = jabber.Client(‘my.openfire.host’)

cx.connect()

cx.auth(‘myuser’, ‘mypass’, ‘mynicename’)

cx.sendInitPresence()

msg = xmpp.Message(‘mybuddy’, ‘This is a test message.’)

msg.setType(‘chat’)

cx.send(msg)

The message never makes it to the destination user. Do you see what I’m doing wrong?

What are you looking to do?

First off:

  1. connect to the server

  2. send message to user

  3. disconnect

Ultimately:

  1. connect to server

  2. join a chat room

  3. drop message in chat room

  4. disconnect

I never need to receive messages as this will be a part of an alert system.

Using jabber (as far as I can see) you need to write the message in XML. For example:

x.write(“This is the message”)

Does .write() actually do the sending? I’m sorry if I sound like a novice but I am and there isn’t any good documentation on this…

Could you modify your original example to send a message?

I am connecting successfully as I see the user come online but the message never reaches the destination user…

Ok, I have an xml message working. The problem was the username(s). I logged into my admin interface and found went to my username’s roster details and found that openfire was naming the users with an @my-server-name which was required when sending…

Now I just need to figure out how to send a message to a chatroom…

Yes, full address to recipeint is needed. I haven’t used chatrooms with XMPP, be interesting to see how you get on. I’ll help debug any issues if you need it.

I ended up using sleekxmp and wrote a script to:

  1. connect to server

  2. join a chat room

  3. drop message in chat room

  4. disconnect

I really hope this helps someone…


import sys

import sleekxmpp

import ssl

sys.setdefaultencoding(‘utf8’)

class MUCBot(sleekxmpp.ClientXMPP):

def init(self, CHAT_USER, CHAT_PASSWORD, CHAT_ROOM, CHAT_NICKNAME):

sleekxmpp.ClientXMPP.init(self, CHAT_USER, CHAT_PASSWORD)

self.room = CHAT_ROOM

self.nick = CHAT_NICKNAME

self.add_event_handler(“session_start”, self.start)

def start(self, event):

self.plugin[‘xep_0045’].joinMUC(self.CHAT_ROOM, self.CHAT_NICKNAME)

self.send_message(mto=self.CHAT_ROOM, mbody=“Sorry about spamming the chat…again.”, mtype=‘groupchat’)

self.disconnect()

if name == ‘main’:

CHAT_USER=’@<server_or_ip>’

CHAT_PASSWORD=’’

CHAT_ROOM=’<chat_room_name>@<full_domain_name>’

CHAT_NICKNAME=’<name_you_wish_to_post_chat_as>’

xmpp = MUCBot(CHAT_USER, CHAT_PASSWORD, CHAT_ROOM, CHAT_NICKNAME)

xmpp.register_plugin(‘xep_0030’) # Service Discovery

xmpp.register_plugin(‘xep_0045’) # Multi-User Chat

xmpp.register_plugin(‘xep_0199’) # XMPP Ping

xmpp.ssl_version = ssl.PROTOCOL_SSLv3

Connect to the XMPP server and start processing XMPP stanzas.

if xmpp.connect():

xmpp.process()

print(“Done”)

else:

print(“Unable to connect.”)