Search code examples
pythonubuntuxmppxmpppy

Python-XMPP traceback from xtalk.py


I have Ubuntu 12.10 with Python 2.7 and am using python-xmpp library (xmpppy) I'm able to connect to my XMPP server (ejabberd) and send IM's to a user, by using the example script called xsend.py

When I attempt to use the test script xtalk.py then I am able to again connect to xmpp, auth, and send a message. This script also should allow me to recieve a reply back from the person I'm sending messages to.

When I run the program, this happens:

root@domU:/home/ubuntu# python xtalk.py [email protected]
An error occurred while looking up _xmpp-client._tcp.xmpp.mydomain.com
connected with tls
authenticated using sasl
I am sending this message from xtalk.py to [email protected]
My message was recieved, and I'm sending another one now
That was recieved to. Now I'm going to reply to myself. 
Traceback (most recent call last):
  File "xtalk.py", line 77, in <module>
    cl.Process(1)
  File "/usr/lib/python2.7/dist-packages/xmpp/dispatcher.py", line 303, in dispatch
    handler['func'](session,stanza)
  File "xtalk.py", line 18, in xmpp_message
    sys.stdout.write(event.getBody() + '\n')
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

I'm not sure where to start troubleshooting this. Can anyone give me a tip?

Specifically what's happening is, I can run xtalk.py and send messages to users, but as soon as a user types the first letter of a response (using the pigin client), the python program crashes with that traceback.

Basically, I can send messages out with this script but cannot receive them back. I think the reason could be something to do with XMPP informing this program that the user is typing, because the error doesn't occur until I press a keystroke in the pigin client to reply to the chat. If I want to reply with "Hello!" then as soon as I press h on the pigin client, the python program on the server crashes. I don't even get to send the message.

One other VERY interesting point: I can two way chat fine using this script if I use the Xabber chat client on my android. I just can't two way chat with this script and a desktop Pigin client...


Solution

  • The problem is with these lines in xtalk.py:

        if type in ['message', 'chat', None] and fromjid == self.remotejid:
            sys.stdout.write(event.getBody() + '\n')
    

    It assumes message stanzas always contain a <body> tag (which cotains the actual text of the message). This is not true: typing notifications, for example, are sent as messages that don't (always) contain a body.

    You should replace these lines with something like:

        if type in ['message', 'chat', None] and fromjid == self.remotejid and event.getBody():
            sys.stdout.write(event.getBody() + '\n')