简体   繁体   English

如何解码Mongo数据库中的芹菜结果?

[英]How to decode celery result from the Mongo DB?

When I execute the task using celery where backend is Mongo DB, It is storing the result in the form of BinData(0,"gAJLEy4=") in the database. 当我使用后端为Mongo DB的芹菜执行任务时,它将结果以BinData(0,"gAJLEy4=")的形式存储在数据库中。

How can we read this 'result' data from the Mongo DB and decode it to string? 我们如何从Mongo数据库中读取此“结果”数据并将其解码为字符串?

I want to write a new python script where it reads all the results from the Mongo db. 我想编写一个新的python脚本,从中读取Mongo数据库的所有结果。

Is there any direct API available in the celery result module or in pymongo to process this result? celery结果模块或pymongo中是否有任何直接API可用于处理此结果?

In my case the result will be the HTML source of web pages (ie crawled data) 就我而言,结果将是网页的HTML来源(即抓取的数据)

Got an answer. 得到了答案。 By default, Celery is storing the result as a pickle object in the data store. 默认情况下,Celery将结果作为泡菜对象存储在数据存储中。 We can retrive this value by calling a function pickle.loads 我们可以通过调用函数pickle.loads来检索此值。

import pickle
# Connect db
# Fetch record from the collection
str_result = pickle.loads(c['result'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM