Python2.6 xmpp Jabber Error

I am using xmpp with python and want to create a simple client to communicate with gmail I would.

#!/usr/bin/python import xmpp login = 'Your.Login' # @gmail.com pwd = 'YourPassword' cnx = xmpp.Client('gmail.com') cnx.connect( server=('talk.google.com',5223) ) cnx.auth(login,pwd, 'botty') cnx.send( xmpp.Message( " YourFriend@gmail.com " ,"Hello World form Python" ) ) 

When I run the last line, I get an exception

IOError: disconnected from the server.

Also, when I run other statements, I get debugging messages in the console.

What could be the problem and how to solve it?

+4
source share
4 answers

Here's how they did it on my PyTalk client .

Do not forget @ gmail.com in the user ID.

I think you should try connecting talk.google.com to port 5222.

Also try specifying ressource for auth.

 import xmpp import sys userID = ' Your.Login@gmail.com ' password = 'YourPassword' ressource = 'Script' jid = xmpp.protocol.JID(userID) jabber = xmpp.Client(jid.getDomain(), debug=[]) connection = jabber.connect(('talk.google.com',5222)) if not connection: sys.stderr.write('Could not connect\n') else: sys.stderr.write('Connected with %s\n' % connection) auth = jabber.auth(jid.getNode(), password, ressource) if not auth: sys.stderr.write("Could not authenticate\n") else: sys.stderr.write('Authenticate using %s\n' % auth) jabber.sendInitPresence(requestRoster=1) jabber.send(xmpp.Message( " YourFriend@gmail.com " ,"Hello World form Python" )) 

By the way, he is very close to Philip Answer

+6
source

Try this piece of code. I could not handle the error conditions for simplicity.

 import xmpp login = 'Your.Login' # @gmail.com pwd = 'YourPassword' jid = xmpp.protocol.JID(login) cl = xmpp.Client(jid.getDomain(), debug=[]) if cl.connect(('talk.google.com',5223)): print "Connected" else: print "Connectioned failed" if cl.auth(jid.getNode(), pwd): cl.sendInitPresence() cl.send(xmpp.Message( " YourFriend@gmail.com " ,"Hello World form Python" )) else: print "Authentication failed" 


To disable debugging messages, go debug = [] for the second parameter in the constructor of the Client class:

 cl = xmpp.Client(jid.getDomain(), debug=[]) 
+1
source

I think you should write this. I am testing it in python 2.7 with xmpppy 0.5.0rc1 and IT: P :) works very well:

 import xmpp login = 'your mail@gmail.com ' # @gmail.com pwd = 'your pass' text='Hello worlD!' tojid='your friend @gmail.com' jid = xmpp.protocol.JID(login) cl = xmpp.Client(jid.getDomain(), debug=[]) if cl.connect(('talk.google.com',5223)): print "Connected" else: print "Connectioned failed" if cl.auth(jid.getNode(), pwd): cl.sendInitPresence() cl.send(xmpp.protocol.Message(tojid,text)) else: print "Authentication failed" 
+1
source

It seems to me that you need to call sendInitPresence before sending the first message:

 ... cnx.auth(login,pwd, 'botty') cnx.sendInitPresence() cnx.send( xmpp.Message( " YourFriend@gmail.com " ,"Hello World form Python" ) ) 
0
source

All Articles