我正在尝试按照教程https://www.rabbitmq.com/tutorials/tutorial-one-python.html,并将命令复制到以下脚本send.py
中:
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='', routing_key='hello', body='Hello World!')
print(" [x] Sent 'Hello Wolrd!'")
connection.close()
但是,当我尝试运行此脚本时,收到以下错误消息:
kurt@kurt-ThinkPad:~/Documents/Scratch$ python send.py
Traceback (most recent call last):
File "send.py", line 4, in <module>
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 339, in __init__
self._process_io_for_connection_setup()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 374, in _process_io_for_connection_setup
self._open_error_result.is_ready)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 410, in _flush_output
self._impl.ioloop.poll()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/select_connection.py", line 602, in poll
self._process_fd_events(fd_event_map, write_only)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/select_connection.py", line 443, in _process_fd_events
handler(fileno, events, write_only=write_only)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 364, in _handle_events
self._handle_read()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 412, in _handle_read
return self._handle_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 288, in _handle_disconnect
self._adapter_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/select_connection.py", line 95, in _adapter_disconnect
super(SelectConnection, self)._adapter_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 154, in _adapter_disconnect
self._check_state_on_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 173, in _check_state_on_disconnect
raise exceptions.ProbableAuthenticationError
pika.exceptions.ProbableAuthenticationError
从我在pika.exceptions.ProbableAuthenticationError when trying to send message to remote queue中读到的内容,这是因为从RabbitMQ 3.3开始,guest/guest
用户名/密码组合只能在本地使用。但是,解决问题的说明并不完全清楚。我如何调整脚本以创建新用户(或使其以任何其他方式工作)?