SleekXMPP icon indicating copy to clipboard operation
SleekXMPP copied to clipboard

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

Open ajparkerbis opened this issue 8 years ago • 3 comments

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='[email protected]',
                    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

ajparkerbis avatar Oct 12 '17 16:10 ajparkerbis

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

LuccoJ avatar May 23 '18 23:05 LuccoJ

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

  • https://github.com/fritzy/SleekXMPP/commits/develop

Have you a patch? Can you create a PR?

Neustradamus avatar Apr 08 '19 02:04 Neustradamus

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 [email protected] -t [email protected] -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.

valholl avatar Nov 05 '19 14:11 valholl