Reputation: 556
I'm trying to send an XMPP message using Python but I can't get it to work. It seems to be failing at the authentication step. I took this example from a previous question and set up a gmail account for testing.
import xmpp
username = '[email protected]'
passwd = 'ThePass123'
to='[email protected]'
msg='hello :)'
client = xmpp.Client('gmail.com')
client.connect(server=('talk.google.com',5223))
client.auth(username, passwd, 'botty')
client.sendInitPresence()
message = xmpp.Message(to, msg)
message.setAttr('type', 'chat')
client.send(message)
There's lots of debug output but this is the part that tells me it fails
DEBUG: socket sent <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">cmFuZG9tdGVzdDYwM0BnbWFpbC5jb21AZ21haWwuY29tAHJhbmRvbXRlc3Q2MDNAZ21haWwuY29tAFRoZVBhc3MxMjM=</auth>
DEBUG: socket got <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
<invalid-authzid/>
</failure>
</stream:stream>
DEBUG: dispatcher ok Got urn:ietf:params:xml:ns:xmpp-sasl/failure stanza
DEBUG: dispatcher ok Dispatching failure stanza with type-> props-> [u'urn:ietf:params:xml:ns:xmpp-sasl'] id->None
DEBUG: sasl error Failed SASL authentification: <invalid-authzid />
But then I also get this at the end
DEBUG: socket sent <presence id="2" />
DEBUG: socket sent <message to="[email protected]" type="chat" id="3">
<body>hello :)</body>
</message>
I've tried this xmpppy and sleekxmpp and the result is the same. This area is new to me so I'm probably making a newbie mistake, anyone have any ideas?
thanks
Upvotes: 3
Views: 4713
Reputation: 3144
Your problem is not python-specific nor library specific. When you call xmpp.Client('gmail.com')
you are specifying the domain part of the username as "gmail.com". Therefore, you should omit that from the username you're using.
Amend your third line to this:
username = 'randomtest603'
It should work(I tried it with my own account after generating an application specific password for this test and it worked only if I omitted the '@gmail.com' from the username, otherwise I got the same error as you).
Upvotes: 3