armchair dot tech
Sending messages using xmpppy | HOME | ABOUT | TAGS

April 5, 2011 | TAGS:

In continuing working with XMPP and Python, I managed to get xmpppy working.

This proved to be particularly tricky because xmpppy uses some outdated modules like md5 and sha.  It also relies on some dns functions which no longer seem to work.

I was able to use the sample script “” that the project provides.  The big thing is that I had to specify and the port number directly in the connect command.

If I did not specify the servername, I would get the error:
 An error occurred while looking up

NOTE: DNS is configured correctly for the domain I was practicing with, but the xmpppy code was not able to resolve it.

To run the script, simply execute;

./ [email protected]  text to send

The Script:


$Id:,v 1.8 2006/10/06 12:30:42 normanr Exp $

import sys,os,xmpp,time

if len(sys.argv) < 2:
    print “Syntax: xsend JID text”

text=' ‘.join(sys.argv[2:])


jidparams[‘jid’]=‘[email protected]
jidparams[‘password’] = ‘123456’


con=cl.connect((‘’,5222),  use_srv=False)

if not con:
    print ‘could not connect!’
print ‘connected with’,con
if not auth:
    print ‘could not authenticate!’
print ‘authenticated using’,auth

cl.SendInitPresence(requestRoster=0)   # you may need to uncomment

this for old server
print ‘sent message with id’,id

time.sleep(1)   # some older servers will not send the message if you disconnect immediately after sending