美文网首页
django celery 执行异常

django celery 执行异常

作者: 鸟它鸟 | 来源:发表于2019-02-13 21:51 被阅读0次

    配置好了django celery,启动celery正常,但是一下发任务就抛异常
    AttributeError: 'str' object has no attribute 'items'

    具体的信息如下(为啥贴这么多log,为了好检索...)

    (python36) [root@wk-api wk_api]# python manage.py celery worker -l info
    /home/python36/lib/python3.6/site-packages/celery/platforms.py:812: RuntimeWarning: You are running the worker with superuser privileges, which is
    absolutely not recommended!
    
    Please specify a different user using the -u option.
    
    User information: uid=0 euid=0 gid=0 egid=0
    
      uid=uid, euid=euid, gid=gid, egid=egid,
    [2019-02-13 18:07:07,175: WARNING/MainProcess] /home/python36/lib/python3.6/site-packages/celery/apps/worker.py:161: CDeprecationWarning:
    Starting from version 3.2 Celery will refuse to accept pickle by default.
    
    The pickle serializer is a security concern as it may give attackers
    the ability to execute any command.  It's important to secure
    your broker from unauthorized access when using pickle, so we think
    that enabling pickle should require a deliberate action and not be
    the default choice.
    
    If you depend on pickle then you should set a setting to disable this
    warning and to be sure that everything will continue working
    when you upgrade to Celery 3.2::
    
        CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']
    
    You must only enable the serializers that you will actually use.
    
    
      warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED))
    
     -------------- celery@wk-api v3.1.26.post2 (Cipater)
    ---- **** -----
    --- * ***  * -- Linux-3.10.0-957.el7.x86_64-x86_64-with-centos-7.6.1810-Core
    -- * - **** ---
    - ** ---------- [config]
    - ** ---------- .> app:         default:0x7f1e00e5d6d8 (djcelery.loaders.DjangoLoader)
    - ** ---------- .> transport:   redis://127.0.0.1:6379/0
    - ** ---------- .> results:
    - *** --- * --- .> concurrency: 2 (prefork)
    -- ******* ----
    --- ***** ----- [queues]
     -------------- .> celery           exchange=celery(direct) key=celery
    
    
    [tasks]
      . sendmail
      . touchfile
      . wk_api.celery.debug_task
    
    [2019-02-13 18:07:07,296: INFO/MainProcess] Connected to redis://127.0.0.1:6379/0
    [2019-02-13 18:07:07,305: INFO/MainProcess] mingle: searching for neighbors
    
    [2019-02-13 18:07:08,309: INFO/MainProcess] mingle: all alone
    [2019-02-13 18:07:08,324: WARNING/MainProcess] /home/python36/lib/python3.6/site-packages/djcelery/loaders.py:133: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
      warn('Using settings.DEBUG leads to a memory leak, never '
    [2019-02-13 18:07:08,325: WARNING/MainProcess] /home/python36/lib/python3.6/site-packages/celery/fixups/django.py:265: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
      warnings.warn('Using settings.DEBUG leads to a memory leak, never '
    [2019-02-13 18:07:08,325: WARNING/MainProcess] celery@wk-api ready.
    
    
    [2019-02-13 18:07:21,708: ERROR/MainProcess] Unrecoverable error: AttributeError("'str' object has no attribute 'items'",)
    Traceback (most recent call last):
      File "/home/python36/lib/python3.6/site-packages/celery/worker/__init__.py", line 206, in start
        self.blueprint.start(self)
      File "/home/python36/lib/python3.6/site-packages/celery/bootsteps.py", line 123, in start
        step.start(parent)
      File "/home/python36/lib/python3.6/site-packages/celery/bootsteps.py", line 374, in start
        return self.obj.start()
      File "/home/python36/lib/python3.6/site-packages/celery/worker/consumer.py", line 280, in start
        blueprint.start(self)
      File "/home/python36/lib/python3.6/site-packages/celery/bootsteps.py", line 123, in start
        step.start(parent)
      File "/home/python36/lib/python3.6/site-packages/celery/worker/consumer.py", line 884, in start
        c.loop(*c.loop_args())
      File "/home/python36/lib/python3.6/site-packages/celery/worker/loops.py", line 76, in asynloop
        next(loop)
      File "/home/python36/lib/python3.6/site-packages/kombu/async/hub.py", line 340, in create_loop
        cb(*cbargs)
      File "/home/python36/lib/python3.6/site-packages/kombu/transport/redis.py", line 1019, in on_readable
        self._callbacks[queue](message)
      File "/home/python36/lib/python3.6/site-packages/kombu/transport/virtual/__init__.py", line 534, in _callback
        self.qos.append(message, message.delivery_tag)
      File "/home/python36/lib/python3.6/site-packages/kombu/transport/redis.py", line 146, in append
        pipe.zadd(self.unacked_index_key, delivery_tag, time()) \
      File "/home/python36/lib/python3.6/site-packages/redis/client.py", line 2320, in zadd
        for pair in iteritems(mapping):
      File "/home/python36/lib/python3.6/site-packages/redis/_compat.py", line 122, in iteritems
        return iter(x.items())
    AttributeError: 'str' object has no attribute 'items'
    

    网上翻腾了半天,最后发现是redis版本太高导致的

    (python36) [root@wk-api wk_api]# pip list|grep redis
    celery-with-redis       3.0
    redis                   3.1.0
    

    卸载redis-3.1.0

    (python36) [root@wk-api wk_api]# pip uninstall redis
    Uninstalling redis-3.1.0:
      Would remove:
        /home/python36/lib/python3.6/site-packages/redis-3.1.0.dist-info/*
        /home/python36/lib/python3.6/site-packages/redis/*
    Proceed (y/n)? y
      Successfully uninstalled redis-3.1.0
    

    安装redis-2.10.6

    (python36) [root@wk-api wk_api]# pip install redis==2.10.6
    Looking in indexes: http://pypi.douban.com/simple
    Collecting redis==2.10.6
      Downloading http://pypi.doubanio.com/packages/3b/f6/7a76333cf0b9251ecf49efff635015171843d9b977e4ffcf59f9c4428052/redis-2.10.6-py2.py3-none-any.whl (64kB)
        100% |████████████████████████████████| 71kB 2.8MB/s
    Installing collected packages: redis
    Successfully installed redis-2.10.6
    

    然后测试就正常了

    相关文章

      网友评论

          本文标题:django celery 执行异常

          本文链接:https://www.haomeiwen.com/subject/xxyjeqtx.html