zaqar transport is broken with python3
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
zaqar |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
In https:/
...
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 = Message(
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 _SelectorSocket
handle: <Handle _SelectorSocket
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/
2019-02-27 14:22:21.002 1 ERROR asyncio self._callback(
2019-02-27 14:22:21.002 1 ERROR asyncio File "/usr/lib64/
2019-02-27 14:22:21.002 1 ERROR asyncio self._protocol.
2019-02-27 14:22:21.002 1 ERROR asyncio File "/usr/lib/
2019-02-27 14:22:21.002 1 ERROR asyncio headers = Message(
2019-02-27 14:22:21.002 1 ERROR asyncio File "/usr/lib64/
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.
ive\r\nContent-
a = Message(s)
print(str(a))
╭─michele@holtby ~ 11:00:42
╰─$ python2 bugmime.py
Host: 192.168.24.1:46643
User-Agent: python-
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/
raise TypeError('Argument is not an instance of Message')
TypeError: Argument is not an instance of Message
https:/ /review. openstack. org/#/c/ 639983/