[rabbitmq-discuss] Python Pika Unicode error

9ners jay0555 at hotmail.com
Tue Mar 12 22:16:59 GMT 2013


getting the following while trying to receive raw data (from UDP source
routed to rabbitmq exchange). Text or Syslog format works alright but errors
out with raw message types. Please help

Exit press CTRL+C
Traceback (most recent call last):
  File "receive_logs.py", line 27, in <module>
    channel.start_consuming()
  File
"/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py",
line 771, in start_consuming
    self.connection.process_data_events()
  File
"/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py",
line 129, in process_data_events
    if self._handle_read():
  File
"/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py",
line 232, in _handle_read
    super(BlockingConnection, self)._handle_read()
  File "/usr/lib/python2.6/site-packages/pika/adapters/base_connection.py",
line 307, in _handle_read
    self._on_data_available(data)
  File "/usr/lib/python2.6/site-packages/pika/connection.py", line 1141, in
_on_data_available
    consumed_count, frame_value = self._read_frame()
  File "/usr/lib/python2.6/site-packages/pika/connection.py", line 1208, in
_read_frame
    return frame.decode_frame(self._frame_buffer)
  File "/usr/lib/python2.6/site-packages/pika/frame.py", line 240, in
decode_frame
    method.decode(frame_data, 4)
  File "/usr/lib/python2.6/site-packages/pika/spec.py", line 1902, in decode
    self.routing_key = encoded[offset:offset + length].decode('utf8')
  File "/usr/lib64/python2.6/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 26-27:
invalid continuation byte


Code :
#!/usr/bin/env python
import pika
import sys

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='localhost'))
channel = connection.channel()

#channel.exchange_declare(exchange='topic_logs',type='topic')

result = channel.queue_declare(exclusive=False)
queue_name = result.method.queue

channel.queue_bind(exchange='collector.raw',
                       queue=queue_name,
                       routing_key="#")

print ' [*] Waiting for logs. To exit press CTRL+C'

def callback(ch, method, properties, body):
    print " [x] %r:%r" % (method.routing_key, body,)

channel.basic_consume(callback,
                      queue=queue_name,
                      no_ack=True)

channel.start_consuming()






--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/Python-Pika-Unicode-error-tp25416.html
Sent from the RabbitMQ mailing list archive at Nabble.com.


More information about the rabbitmq-discuss mailing list