Skip to content

Instantly share code, notes, and snippets.

@hntrmrrs
Created May 6, 2011 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hntrmrrs/959237 to your computer and use it in GitHub Desktop.
Save hntrmrrs/959237 to your computer and use it in GitHub Desktop.
pika issue #34
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
# Fix import paths
base_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(base_dir)
import pika
from pika.adapters.blocking_connection import BlockingConnection
def main():
"Example which exhibits the failure case"
cparams = pika.ConnectionParameters(
host='127.0.0.1',
port=5672,
virtual_host='/',
credentials=pika.PlainCredentials('guest', 'guest'))
connection = BlockingConnection(cparams)
channel = connection.channel()
test_exchange = u'foo£'
try:
result = channel.exchange_declare(exchange=test_exchange, auto_delete=True)
print 'exchange_declare: %r' % result
except UnicodeDecodeError:
import traceback
traceback.print_exc()
print
print 'caught a UnicodeDecodeError, converting'
if isinstance(test_exchange, unicode):
test_exchange = test_exchange.encode('utf-8')
channel = connection.channel()
result = channel.exchange_declare(exchange=test_exchange, auto_delete=True)
print 'exchange_declare (2): %r' % result
print 'Exiting...'
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment