gmr / rabbitpy

A pure python, thread-safe, minimalistic and pythonic RabbitMQ client library
http://rabbitpy.readthedocs.org
BSD 3-Clause "New" or "Revised" License
242 stars 58 forks source link

Getting typerror but, can't traceback to which var #114

Closed vivekanand1101 closed 6 years ago

vivekanand1101 commented 6 years ago

I am trying to use rabbitpy as rmq producer inside a celery task (once the task is completed, then send a msg to different service). I am getting this:

Nov 22 22:47:44 batman celery[18571]: [2017-11-22 17:17:44,421: WARNING/ForkPoolWorker-1] Exception in thread 0x7fab29e51290-io:
Nov 22 22:47:44 batman celery[18571]: Traceback (most recent call last):
Nov 22 22:47:44 batman celery[18571]:   File "/usr/lib64/python2.7/threading.py", line 804, in __bootstrap_inner
Nov 22 22:47:44 batman celery[18571]:     self.run()
Nov 22 22:47:44 batman celery[18571]:   File "/srv/ethcld/lib/python2.7/site-packages/rabbitpy/io.py", line 411, in run
Nov 22 22:47:44 batman celery[18571]:     self._loop.run()
Nov 22 22:47:44 batman celery[18571]:   File "/srv/ethcld/lib/python2.7/site-packages/rabbitpy/io.py", line 207, in run
Nov 22 22:47:44 batman celery[18571]:     self._poll()
Nov 22 22:47:44 batman celery[18571]:   File "/srv/ethcld/lib/python2.7/site-packages/rabbitpy/io.py", line 252, in _poll
Nov 22 22:47:44 batman celery[18571]:     self._data.write_buffer.append(frame.marshal(data[1], data[0]))
Nov 22 22:47:44 batman celery[18571]:   File "/srv/ethcld/lib/python2.7/site-packages/pamqp/frame.py", line 103, in marshal
Nov 22 22:47:44 batman celery[18571]:     return _marshal_method_frame(frame_value, channel_id)
Nov 22 22:47:44 batman celery[18571]:   File "/srv/ethcld/lib/python2.7/site-packages/pamqp/frame.py", line 255, in _marshal_method_frame
Nov 22 22:47:44 batman celery[18571]:     frame_value.marshal())
Nov 22 22:47:44 batman celery[18571]:   File "/srv/ethcld/lib/python2.7/site-packages/pamqp/specification.py", line 191, in marshal
Nov 22 22:47:44 batman celery[18571]:     output.append(encode.by_type(data_value, data_type))
Nov 22 22:47:44 batman celery[18571]:   File "/srv/ethcld/lib/python2.7/site-packages/pamqp/encode.py", line 366, in by_type
Nov 22 22:47:44 batman celery[18571]:     return short_string(value)
Nov 22 22:47:44 batman celery[18571]:   File "/srv/ethcld/lib/python2.7/site-packages/pamqp/encode.py", line 191, in short_string
Nov 22 22:47:44 batman celery[18571]:     raise TypeError("bytes, str, or unicode required")
Nov 22 22:47:44 batman celery[18571]: TypeError: bytes, str, or unicode required

The command which produces this is:

publisher(exchange='abcd', queue='abc', routing_key='ab.cd', msg=somedict)

The definition of publisher method is:

def publisher(exchange, queue, routing_key, msg):
    with rabbitpy.Connection(settings.BROKER_URL) as conn:
        with conn.channel() as channel:
            exchange = rabbitpy.TopicExchange(channel, exchange)
            exchange.declare()
            queue = rabbitpy.Queue(channel, queue, durable=True)
            queue.declare()
            queue.bind(exchange, exchange)
            message = rabbitpy.Message(
                channel,
                json.dumps(msg),
                {
                    'content_type': 'application/json',
                    'delivery_mode': 1,
                    'message_type': 'some random text, i don't know what this is for',
                    'timestamp': datetime.datetime.now(),
                    'message_id': uuid.uuid1()
                }
            )

            message.publish(exchange, routing_key)

I am not able to figure out what's the problem here :/

vivekanand1101 commented 6 years ago

wow, found my stupidity. I can't believe i left the office in frustration last night 😢