我正在尝试使用pika与Rabbitmq连接
def get_connection():
credentials = pika.PlainCredentials(MQ_USER, MQ_PASS)
connection = pika.BlockingConnection(pika.ConnectionParameters(MQ_SERVER, 5672, '/', credentials))
return connection
我可以在rabbitmqctl中使用这些凭据,输出如下所示:
# rabbitmqctl authenticate_user user pass
Authenticating user "user" ...
Success
我还试图只将字符串与函数中的值一起使用,并得到相同的错误。我也可以在Rabbitmq端口上使用telnet访问,并且用户可以访问该频道。
执行python代码时出现此错误:
Internal Server Error: /api/analysis/stream/finish/
Traceback (most recent call last):
File "/wearehuman/wechat_fun_api/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/wearehuman/wechat_fun_api/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/wearehuman/wechat_fun_api/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/wearehuman/wechat_fun_api/core/views.py", line 2465, in record_finsh
inform_process(video.filename)
File "/wearehuman/wechat_fun_api/core/views.py", line 702, in inform_process
con = get_connection()
File "/wearehuman/wechat_fun_api/base/rabitmq.py", line 7, in get_connection
connection = pika.BlockingConnection(pika.ConnectionParameters(host=MQ_SERVER, port=5672, virtual_host='/', credentials=credentials))
File "/wearehuman/wechat_fun_api/venv/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 360, in __init__
self._impl = self._create_connection(parameters, _impl_class)
File "/wearehuman/wechat_fun_api/venv/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 451, in _create_connection
raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AMQPConnectionError
在我看来,即使在下一行出现错误,此行credentials = pika.PlainCredentials(MQ_USER, MQ_PASS)
上还是发生了某些情况。此功能到底有什么作用?关于我在做什么错的任何想法?