You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS部署Django+Celery/Redis环境时出现'timeout'意外关键字参数错误

问题定位与解决方案

这个TypeError: wrapped_func() got an unexpected keyword argument 'timeout'错误,核心原因是Celery/Kombu在调用Redis连接相关函数时传递的timeout参数未被正确处理,以下是针对性的解决步骤:

1. 检查自定义Redis连接逻辑

如果你的Django配置中使用了自定义的Redis连接工厂、连接池或者包装函数(比如通过BROKER_TRANSPORT_OPTIONS配置connection_factory),必须确保这些函数接受并传递所有传入的关键字参数。

比如如果有类似这样的自定义连接代码:

def custom_redis_conn():
    return redis.Redis(host=settings.REDIS_URL, port=6379)

需要修改为:

def custom_redis_conn(**kwargs):
    return redis.Redis(host=settings.REDIS_URL, port=6379, **kwargs)

确保timeout这类参数能被正确传递到Redis客户端。

2. 锁定兼容的依赖版本组合

你当前使用的redis==4.3.4与kombu==5.2.4存在适配冲突,建议降级Redis客户端版本,使用经过验证的兼容组合:

celery==5.2.7
Django==3.1
django-celery-beat==2.3.0
kombu==5.2.4
redis==4.2.2
pip==22.1.2
setuptools==58.0.0

执行以下命令重新安装依赖:

pip uninstall -y redis kombu celery
pip install celery==5.2.7 kombu==5.2.4 redis==4.2.2

3. 校验Broker URL格式

确保CELERY_BROKER_URL(或BROKER_URL)符合Redis 4.x客户端的规范:

# 基础格式
CELERY_BROKER_URL = 'redis://<your-redis-host>:6379/0'
# 带密码的格式
CELERY_BROKER_URL = 'redis://:<your-password>@<your-redis-host>:6379/0'

避免使用过时的redis+socket://格式或自定义的URL参数,防止解析异常。

4. 清理缓存并重启服务

  • 删除项目中的Python缓存目录:rm -rf __pycache__/
  • 清理残留的Celery进程:ps aux | grep celery | grep -v grep | awk '{print $2}' | xargs kill -9
  • 重新启动Celery worker:celery -A core worker --loglevel=INFO

验证步骤

先测试Kombu的连接兼容性,再启动Worker:

from kombu.connection import Connection
from django.conf import settings

conn = Connection(settings.CELERY_BROKER_URL)
conn.connect()
print("Kombu与Redis连接正常")
conn.close()

如果测试通过,再启动Celery Worker即可解决问题。

内容的提问来源于stack exchange,提问作者Lucas Weber

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 03:54:15