Koko
Koko

Reputation: 479

Python XMPP Error : Failed SASL authentification: <incorrect-encoding />

I'm trying to get a TLS XMPP client working using python 2.7.6 on Ubuntu 14.04. I have DEBUG mode enabled and the whole connection looks good up until I get the error message error Failed SASL authentification: <incorrect-encoding />. I've verified the user and password account via a desktop Jabber client. Here is the code I'm using. Any ideas why this is not working?:

#!/usr/bin/python

import xmpp

username= 'testxmpp'
passwd  = 'testtesttest'
to='jabber.somedomain.com'
msg='hello :)'



client = xmpp.Client('jabber.somedomain.com')
client.connect(server=('jabber.somedomain.com',5222))
client.auth(username, passwd, 'botty')
client.sendInitPresence()
message = xmpp.Message(to, msg)
message.setAttr('type', 'chat')
client.send(message)

This is an excerpt of the DEBUG output from the program:

DEBUG: socket       got   <failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
      <incorrect-encoding/>
      </failure>
    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: <incorrect-encoding />
    DEBUG: sasl         stop  Plugging <xmpp.auth.SASL instance at 0x7f7c40711950> out of <xmpp.client.Client instance at 0x7f7c40784c68>.
    DEBUG: roster       start Plugging <xmpp.roster.Roster instance at 0x7f7c40711d40> into <xmpp.client.Client instance at 0x7f7c40784c68>
    DEBUG: dispatcher   info  Registering handler <bound method Roster.RosterIqHandler of <xmpp.roster.Roster instance at 0x7f7c40711d40>> for "iq" type->result ns->jabber:iq:roster(jabber:client)
    DEBUG: dispatcher   info  Registering handler <bound method Roster.RosterIqHandler of <xmpp.roster.Roster instance at 0x7f7c40711d40>> for "iq" type->set ns->jabber:iq:roster(jabber:client)
    DEBUG: dispatcher   info  Registering handler <bound method Roster.PresenceHandler of <xmpp.roster.Roster instance at 0x7f7c40711d40>> for "presence" type-> ns->(jabber:client)
    DEBUG: socket       sent  <iq type="get" id="22">
      <query xmlns="jabber:iq:roster" />

Upvotes: 1

Views: 909

Answers (1)

Koko
Koko

Reputation: 479

In case it helps someone else, had to make an edit in the /usr/lib/python2.7/dist-packages/xmpp/auth.py file:

...
      elif "PLAIN" in mecs:
            sasl_data='%s\x00%s\x00%s'%(self.username+'@'+self._owner.Server,self.username,self.password)
            # ko - 2017-01-09 - fix for 'incorrect-encoding' error 
            # node=Node('auth',attrs={'xmlns':NS_SASL,'mechanism':'PLAIN'},payload=[base64.encodestring(sasl_data)])
            node=Node('auth',attrs={'xmlns':NS_SASL,'mechanism':'PLAIN'},payload=[base64.encodestring(sasl_data).replace('\r','').replace('\n','')]) 
        else:
...

https://github.com/normanr/xmpppy/blob/master/xmpp/auth.py

Upvotes: 1

Related Questions