Celery 错误:“str 对象不可调用”,getstate() 函数是一个字符串
当我尝试将任务传递给 Celery 工作人员时,我收到此错误。这是回溯
Traceback:
File "/home/vivek/xpython/lib/python2.6/site-packages/Django-1.3-py2.6.egg/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/vivek/projects/engine/engine/web/models.py" in fb_sync
53. process_metadata.delay(self, wrapper)
File "/home/vivek/xpython/lib/python2.6/site-packages/celery-2.2.7-py2.6.egg/celery/task/base.py" in delay
338. return self.apply_async(args, kwargs)
File "/home/vivek/xpython/lib/python2.6/site-packages/celery-2.2.7-py2.6.egg/celery/task/base.py" in apply_async
460. **options)
File "/home/vivek/xpython/lib/python2.6/site-packages/celery-2.2.7-py2.6.egg/celery/app/amqp.py" in delay_task
230. send(body, exchange=exchange, **extract_msg_options(kwargs))
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/compat.py" in send
101. return self.publish(*args, **kwargs)
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/messaging.py" in publish
124. compression, headers)
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/messaging.py" in _prepare
147. body) = encode(body, serializer=serializer)
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/serialization.py" in encode
119. payload = encoder(data)
File "/home/vivek/xpython/lib/python2.6/copy_reg.py" in _reduce_ex
84. dict = getstate()
Exception Type: TypeError at /login/
Exception Value: 'str' object is not callable
/home/vivek/xpython/lib/python2.6/copy_reg.py in _reduce_ex
dict = getstate() ...
local variables
{'args': (<web.models.User object at 0x8b47b4c>,<web.fb.Facebook object at 0x8b4fbac>),
'eta': None,
'expires': None,
'id': '8d8e6c0b-a269-4780-9c48-77e689037322',
'kwargs': {},
'retries': 0,
'task': 'web.models.process_likes'}
What is the solution to this problem? When I remove the task decorator, it works fine.
I'm getting this error when I try to pass a task to a Celery worker. Here is the traceback
Traceback:
File "/home/vivek/xpython/lib/python2.6/site-packages/Django-1.3-py2.6.egg/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/vivek/projects/engine/engine/web/models.py" in fb_sync
53. process_metadata.delay(self, wrapper)
File "/home/vivek/xpython/lib/python2.6/site-packages/celery-2.2.7-py2.6.egg/celery/task/base.py" in delay
338. return self.apply_async(args, kwargs)
File "/home/vivek/xpython/lib/python2.6/site-packages/celery-2.2.7-py2.6.egg/celery/task/base.py" in apply_async
460. **options)
File "/home/vivek/xpython/lib/python2.6/site-packages/celery-2.2.7-py2.6.egg/celery/app/amqp.py" in delay_task
230. send(body, exchange=exchange, **extract_msg_options(kwargs))
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/compat.py" in send
101. return self.publish(*args, **kwargs)
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/messaging.py" in publish
124. compression, headers)
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/messaging.py" in _prepare
147. body) = encode(body, serializer=serializer)
File "/home/vivek/xpython/lib/python2.6/site-packages/kombu-1.1.6-py2.6.egg/kombu/serialization.py" in encode
119. payload = encoder(data)
File "/home/vivek/xpython/lib/python2.6/copy_reg.py" in _reduce_ex
84. dict = getstate()
Exception Type: TypeError at /login/
Exception Value: 'str' object is not callable
/home/vivek/xpython/lib/python2.6/copy_reg.py in _reduce_ex
dict = getstate() ...
local variables
{'args': (<web.models.User object at 0x8b47b4c>,<web.fb.Facebook object at 0x8b4fbac>),
'eta': None,
'expires': None,
'id': '8d8e6c0b-a269-4780-9c48-77e689037322',
'kwargs': {},
'retries': 0,
'task': 'web.models.process_likes'}
What is the solution to this problem? When I remove the task decorator, it works fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正尝试将对象传递给无法序列化的任务。尝试传递更简单的数据(让您在任务运行时重新创建复杂对象的信息)。
不确定这是否是错误的实际原因,但无论如何您都不应该将 Django 模型传递给任务。否则你会遇到竞争条件。请参阅有关该主题的 Celery 文档:
将用户对象的唯一键以及识别 Facebook Like 交互所需的任何内容传递为简单的 Python 类型,并使用任务中的该信息来重新创建执行该任务所需的内容。
You are trying to pass an object to a task that cannot be serialized. Try to pass simpler data (information that let's you recreate the complex objects when the task is run).
Not sure if that's the actual cause of your error, but you should not pass Django models to tasks anyway. You will run into race conditions otherwise. See the Celery documentation on the subject:
Pass the unique key for the user object and whatever you need to identify the Facebook Like interaction as simple python types instead, and use that information from within the task to recreate what you need to do the task instead.