I wrote a celery task that sets some values in my database when I click on a button on my web page. Everything is fine. Now I want to write a more complex task (disambiguation_task) that returns a string to my Django view (1.6.5). The code is:
task_id = disambiguation_task.apply_async([json.dumps(json_request)])
async_result = AsyncResult(id=task_id,app=disambiguation_task)
As soon as I try to get the result (async_result.get()), it generates an error:
AsyncResult' object has no attribute 'replace'
with the following traceback:
File "/home/patrick/django/entite-tracker-master/entitetracker/docentites/views.py" in get
466. result = async_result.get()
File "/usr/local/lib/python2.7/dist-packages/celery/result.py" in get
169. no_ack=no_ack,
File "/usr/local/lib/python2.7/dist-packages/celery/backends/amqp.py" in wait_for
155. on_interval=on_interval)
File "/usr/local/lib/python2.7/dist-packages/celery/backends/amqp.py" in consume
225. binding = self._create_binding(task_id)
File "/usr/local/lib/python2.7/dist-packages/celery/backends/amqp.py" in _create_binding
99. name = self.rkey(task_id)
File "/usr/local/lib/python2.7/dist-packages/celery/backends/amqp.py" in rkey
111. return task_id.replace('-', '')
Exception Type: AttributeError at /docentites/nodoc_desamb/news20150305NY501131/
Exception Value: 'AsyncResult' object has no attribute 'replace'
Same error if I try to print async_result.state. Can someone help me with this error? Regards, Patrick
disambiguation_task.apply_async([json.dumps(json_request)])
returns AsyncResult object, not a task id. So simply:
task_result = disambiguation_task.apply_async([json.dumps(json_request)])
# if you need to use the task_id somewhere else
async_result = AsyncResult(id=task_result.id, app=disambiguation_task)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.