fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

mhtml TypeError: 'unicode' object does not support item assignment #475

Open ajparkerbis opened 7 years ago

ajparkerbis commented 7 years ago

We were moving a script from a server with version 1.3.1 of sleekxmpp to 1.3.3 and messages sent via mhtml with a space and then colon : caused a hang or broken parsing of mhtml.

Here is a code snippet:

    fifo = open('/tmp/networking.fifo')
    p_pattern = re.compile('Problem : .*')
r_pattern = re.compile('Resolved : .*')

    while True:
        line = fifo.readline()
        if line:
            if p_pattern.match(line):
                xmpp.send_message(
                    mto='forsyth_issues@conference.bisonline.com',
                    mbody=line.strip(),
                    mtype='groupchat',
                    mhtml="<span style=\'color:#ce1818\'>%(message)s</span>" % { "message" : line }
                )

sending most text to the fifo worked fine - sending Problem: even worked fine. It was Problem : that then caused a hang and prompted the TypeError

The error we see is: TypeError: 'unicode' object does not support item assignment -

and it references the mhtml line.

(there's an elif for the other match and an else - everything was working properly with 1.3.1 and we resolved the issue by rolling the new server back to sleekxmpp 1.3.1 from 1.3.3)

*On CentOS 7.3.1611 with python 2.7.5 and sleekxmpp 1.3.3

LuccoJ commented 6 years ago

Confirming this behavior, with SleekXMPP 1.3.3 and Python 2.7.15 (current Debian Testing):

In [109]: c.send_message("foo@bar", "Hello world")

In [110]: c.send_message("foo@bar", "Hello world", mhtml="Hello <strong>world</strong")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-110-8543c9085cc5> in <module>()
----> 1 c.send_message("foo@bar", "Hello world", mhtml="Hello <strong>world</strong")

~/.local/share/virtualenvs/bot-xPCSx1pa/local/lib/python2.7/site-packages/sleekxmpp/basexmpp.pyc in send_message(self, mto, mbody, msubject, mtype, mhtml, mfrom, mnick)
    542         """
    543         self.make_message(mto, mbody, msubject, mtype,
--> 544                           mhtml, mfrom, mnick).send()
    545 
    546     def send_presence(self, pshow=None, pstatus=None, ppriority=None,

~/.local/share/virtualenvs/bot-xPCSx1pa/local/lib/python2.7/site-packages/sleekxmpp/basexmpp.pyc in make_message(self, mto, mbody, msubject, mtype, mhtml, mfrom, mnick)
    497             message['nick'] = mnick
    498         if mhtml is not None:
--> 499             message['html']['body'] = mhtml
    500         return message
    501 

TypeError: 'unicode' object does not support item assignment
Neustradamus commented 5 years ago

@ajparkerbis @LuccoJ: Always present for "master"?

Have you a patch? Can you create a PR?

valholl commented 5 years ago

Attached is a minimal example that triggers this issue, based on send_client.py from the examples directory; it can be run with ./send_client.py -j somebody@example.org -t somebodyelse@example.net -m '' (the message is ignored and an hardcoded one is used)

send_client.txt

I don't have a patch for SleekXMPP, as this is my first time looking at its code (I'm debugging an issue in software written by somebody else that stopped working, probably between debian jessie (python-sleekxmpp 1.0~beta5) and stable/testing (python(3)-sleekxmpp 1.3.3)).

I've checked the documentation at https://sleekxmpp.readthedocs.io/en/latest/api/basexmpp.html#sleekxmpp.basexmpp.BaseXMPP.send_message and it seems that the declared API hasn't changed, so this looks like a regression.