zaqar transport is broken with python3

Bug #1818046 reported by Michele Baldessari
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
zaqar
Fix Released
Undecided
Unassigned

Bug Description

In https://github.com/openstack/zaqar/blob/master/zaqar/transport/websocket/protocol.py we do the following:
...
try:
    import mimetools
    Message = mimetools.Message
except ImportError:
    from email.mime import message
    Message = message.MIMEMessage
...

        if self._state == 'HEADERS' and b'\r\n\r\n' in self._data:
            headers, self._data = self._data.split(b'\r\n\r\n', 1)
            headers = Message(io.BytesIO(headers))

The above does not work with python3 because it will throw an exception:
2019-02-27 14:22:19.359 1 ERROR asyncio
2019-02-27 14:22:21.002 1 ERROR asyncio [-] Exception in callback _SelectorSocketTransport._read_ready()
handle: <Handle _SelectorSocketTransport._read_ready()>: TypeError: Argument is not an instance of Message
2019-02-27 14:22:21.002 1 ERROR asyncio Traceback (most recent call last):
2019-02-27 14:22:21.002 1 ERROR asyncio File "/usr/lib64/python3.6/asyncio/events.py", line 145, in _run
2019-02-27 14:22:21.002 1 ERROR asyncio self._callback(*self._args)
2019-02-27 14:22:21.002 1 ERROR asyncio File "/usr/lib64/python3.6/asyncio/selector_events.py", line 721, in _read_ready
2019-02-27 14:22:21.002 1 ERROR asyncio self._protocol.data_received(data)
2019-02-27 14:22:21.002 1 ERROR asyncio File "/usr/lib/python3.6/site-packages/zaqar/transport/websocket/protocol.py", line 255, in data_received
2019-02-27 14:22:21.002 1 ERROR asyncio headers = Message(io.BytesIO(headers))
2019-02-27 14:22:21.002 1 ERROR asyncio File "/usr/lib64/python3.6/email/mime/message.py", line 29, in __init__
2019-02-27 14:22:21.002 1 ERROR asyncio raise TypeError('Argument is not an instance of Message')
2019-02-27 14:22:21.002 1 ERROR asyncio TypeError: Argument is not an instance of Message

The problem is that the message class in mimetools is not really compatible with the class in email.mime. Here is a small reproducer to show the issue:
╭─michele@holtby ~ 11:00:40
╰─$ more bugmime.py
import io
try:
    import mimetools
    Message = mimetools.Message
except ImportError:
    from email.mime import message
    Message = message.MIMEMessage

s = io.BytesIO(b'Host: 192.168.24.1:46643\r\nUser-Agent: python-requests/2.20.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-al
ive\r\nContent-Type: application/json\r\nContent-Length: 5349')
a = Message(s)
print(str(a))
╭─michele@holtby ~ 11:00:42
╰─$ python2 bugmime.py
Host: 192.168.24.1:46643
User-Agent: python-requests/2.20.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Type: application/json
Content-Length: 5349
╭─michele@holtby ~ 11:00:47
╰─$ python3 bugmime.py
Traceback (most recent call last):
  File "bugmime.py", line 10, in <module>
    a = Message(s)
  File "/usr/lib64/python3.7/email/mime/message.py", line 29, in __init__
    raise TypeError('Argument is not an instance of Message')
TypeError: Argument is not an instance of Message

Revision history for this message
Michele Baldessari (michele) wrote :
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to zaqar (master)

Reviewed: https://review.openstack.org/639983
Committed: https://git.openstack.org/cgit/openstack/zaqar/commit/?id=ff19fdeb5452f19d8420cfb041aa846bdf58c84e
Submitter: Zuul
Branch: master

commit ff19fdeb5452f19d8420cfb041aa846bdf58c84e
Author: Damien Ciabrini <email address hidden>
Date: Thu Feb 28 11:43:29 2019 +0100

    Python 3: Fix parsing of received notification

    The parsing of incoming notifications is performed with a helper
    which normally resolves to a mimetools class.

    For Python3, package mimetools doesn't exist anymore, and the helper
    resolves to a class with incompatible signature.

    In order to mimick the original helper behaviour and return a message
    object as expected, use a different facility from package email.

    Change-Id: I92f10755f1a98239df3b3a1494207299a3681a84
    Closes-Bug: #1818046
    Co-Authored-By: Michele Baldessari <email address hidden>
    Co-Authored-By: Alex Schultz <email address hidden>

Changed in zaqar:
status: New → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/zaqar 8.0.0.0rc1

This issue was fixed in the openstack/zaqar 8.0.0.0rc1 release candidate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.