Created
May 6, 2011 16:04
-
-
Save hntrmrrs/959237 to your computer and use it in GitHub Desktop.
pika issue #34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 '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