import asyncio
import json
from amqproto.io.asyncio import Connection
from amqproto.protocol import BasicMessage
async def main():
async with Connection(host='127.0.0.1') as connection:
async with connection.get_channel() as channel:
message = BasicMessage(json.dumps({'ok': True}))
await channel.basic_publish(message, routing_key='hello')
$ python test.py
^CTraceback (most recent call last):
File "test.py", line 15, in
loop.run_until_complete(main())
File "/usr/lib64/python3.6/asyncio/base_events.py", line 454, in run_until_complete
self.run_forever()
File "/usr/lib64/python3.6/asyncio/base_events.py", line 421, in run_forever
self._run_once()
File "/usr/lib64/python3.6/asyncio/base_events.py", line 1389, in _run_once
event_list = self._selector.select(timeout)
File "/usr/lib64/python3.6/selectors.py", line 445, in select
fd_event_list = self._epoll.poll(timeout, max_ev)
KeyboardInterrupt
Exception ignored in: <coroutine object main at 0x7f07d348a8e0>
RuntimeError: coroutine ignored GeneratorExit
Task exception was never retrieved
future: <Task finished coro=<Connection._communicate() done, defined at amqproto/amqproto/io/asyncio.py:294> exception=<AMQPError: 505, 60, 40>>
Traceback (most recent call last):
File "amqproto/amqproto/io/asyncio.py", line 307, in _communicate
coroutine = handler(frame)
File "amqproto/amqproto/connection.py", line 162, in handle_frame
return handler(method)
File "amqproto/amqproto/connection.py", line 364, in _receive_ConnectionClose
return self._send_ConnectionCloseOK(exc)
File "amqproto/amqproto/connection.py", line 369, in _send_ConnectionCloseOK
raise _exc
amqproto.protocol.errors.UnexpectedFrame: UNEXPECTED_FRAME - expected content body, got non content body frame instead
While the fix is to encode body into bytes, the error is quite misleading.
Steps to reproduce:
async def main(): async with Connection(host='127.0.0.1') as connection: async with connection.get_channel() as channel: message = BasicMessage(json.dumps({'ok': True})) await channel.basic_publish(message, routing_key='hello')
loop = asyncio.get_event_loop() loop.run_until_complete(main())
$ python test.py ^CTraceback (most recent call last): File "test.py", line 15, in
loop.run_until_complete(main())
File "/usr/lib64/python3.6/asyncio/base_events.py", line 454, in run_until_complete
self.run_forever()
File "/usr/lib64/python3.6/asyncio/base_events.py", line 421, in run_forever
self._run_once()
File "/usr/lib64/python3.6/asyncio/base_events.py", line 1389, in _run_once
event_list = self._selector.select(timeout)
File "/usr/lib64/python3.6/selectors.py", line 445, in select
fd_event_list = self._epoll.poll(timeout, max_ev)
KeyboardInterrupt
Exception ignored in: <coroutine object main at 0x7f07d348a8e0>
RuntimeError: coroutine ignored GeneratorExit
Task exception was never retrieved
future: <Task finished coro=<Connection._communicate() done, defined at amqproto/amqproto/io/asyncio.py:294> exception=<AMQPError: 505, 60, 40>>
Traceback (most recent call last):
File "amqproto/amqproto/io/asyncio.py", line 307, in _communicate
coroutine = handler(frame)
File "amqproto/amqproto/connection.py", line 162, in handle_frame
return handler(method)
File "amqproto/amqproto/connection.py", line 364, in _receive_ConnectionClose
return self._send_ConnectionCloseOK(exc)
File "amqproto/amqproto/connection.py", line 369, in _send_ConnectionCloseOK
raise _exc
amqproto.protocol.errors.UnexpectedFrame: UNEXPECTED_FRAME - expected content body, got non content body frame instead