Flower点击Broker标签报500错误,提示Unable to get queues: ''如何解决?
Flower访问RabbitMQ Broker标签报500错误的解决方案
问题场景
通过Docker启动带management插件的RabbitMQ:
docker run -d -p 5672:5672 -p 15672:15672 rabbitmq:management
容器使用默认凭据guest/guest,主机可通过http://localhost:15672正常访问管理UI。
Celery配置如下:
from celery import Celery celery_app = Celery( main='background-task', broker='amqp://guest@localhost:5672//', backend='mongodb://localhost:27017/tasks', result_extended=True, include=['app.tasks'] ) celery_app.conf.task_routes = { 'add': 'add' }
执行以下命令启动worker,运行正常:
celery --app app.main:celery_app worker --loglevel=INFO -Q add
启动Flower时使用命令:
celery --app app.main:celery_app flower --broker_api=\"http://guest@localhost:15672/api\"
Flower启动后其他标签可正常访问,但点击Broker标签时UI显示Error 500,日志报错:
[E 240708 17:37:30 broker:31] Unable to get queues: '' [E 240708 17:37:30 web:1875] Uncaught exception GET /broker (::1) HTTPServerRequest(protocol='http', host='localhost:5555', method='GET', uri='/broker', version='HTTP/1.1', remote_ip='::1') Traceback (most recent call last): File "/path/to/project/.venv/lib/python3.11/site-packages/tornado/web.py", line 1790, in _execute result = await result ^^^^^^^^^^^^ File "/path/to/project/.venv/lib/python3.11/site-packages/flower/views/broker.py", line 35, in get queues=queues) ^^^^^^ UnboundLocalError: cannot access local variable 'queues' where it is not associated with a value
解决方案
1. 修正Flower启动命令的Broker API参数
启动命令中--broker_api的引号无需转义,且需显式指定完整的用户名和密码(避免权限验证遗漏),正确命令如下:
celery --app app.main:celery_app flower --broker_api=http://guest:guest@localhost:15672/api
2. 验证RabbitMQ管理API的可达性
手动访问http://guest:guest@localhost:15672/api/queues,确认能返回队列的JSON格式数据。若访问失败:
- 用
docker ps检查RabbitMQ容器是否正常运行 - 确认主机端口15672未被其他进程占用
- 验证凭据是否正确(默认
guest/guest,若修改过配置需用对应凭据)
3. 确保目标队列已存在
RabbitMQ的队列默认是延迟创建的,需至少执行一次对应任务才会生成add队列。可以先触发一次add任务,或者在RabbitMQ管理UI的Queues页面手动创建add队列,之后再刷新Flower的Broker标签。
4. 排查版本兼容性问题
部分新版本Flower与RabbitMQ management API存在适配问题,若上述方法无效:
- 尝试安装指定版本的Flower,例如:
pip install flower==2.0.1 - 更换RabbitMQ镜像为稳定版本,例如:
docker run -d -p 5672:5672 -p 15672:15672 rabbitmq:3.12-management
内容的提问来源于stack exchange,提问作者Triet Doan
相关产品推荐
相关产品推荐

