Python pickle错误:无法pickle请求对象

Python pickle错误:无法pickle请求对象,python,celery,pyramid,pickle,Python,Celery,Pyramid,Pickle,我知道不可能对金字塔请求对象进行pickle,但我似乎找不到将请求对象发送到哪里 考虑以下几点: @task def do_consignment_task(store, agent): print "GOTHERE IN TASK" s = sqlahelper.get_session() consign = store.gen_consignment() ca = Agents.by_id(store.consignment_agents_id) co

我知道不可能对金字塔请求对象进行pickle,但我似乎找不到将
请求
对象发送到哪里

考虑以下几点:

@task
def do_consignment_task(store, agent):
    print "GOTHERE IN TASK"
    s = sqlahelper.get_session()
    consign = store.gen_consignment()
    ca = Agents.by_id(store.consignment_agents_id)
    consign.consignment_agents_id = ca.id
    consign.consignment_teamleader_id = ca.ou[0].lead_agents_id
    consign.consignment_timestamp = func.now()
    consign.created_by_agent_id = agent.id
    consign.complete_stamp = func.now()
    consign.sims =  store.sims
    consign.status = "SUCCESS"
    print "GOT BEFORE LOOP " 
    for sim in store.sims:
        if sim in consign.sims:
            continue
        else:
            consign.sims.append(sim)
    s.add(consign)
    transaction.savepoint()
    print "GOT AFTER SAVEPOINT"
    for sim in consign.sims:
        is_reconsign = sim.consignment_agent or sim.consignment_teamlead
        if is_reconsign:
            if not sim.consignment_history:
                sim.consignment_history = []
            sim.consignment_history.append(dict(
                stamp=sim.consignment_timestamp,
                consignment_agent_id=sim.consignment_agents_id,
                consignment_teamleader_id=sim.consignment_teamleader_id,
                by_agent_id=agent.id
            ))
        s.query(
            Sims
        ).filter(
            Sims.iccid == sim.iccid
        ).update(
            {
                "consignment_agents_id": consign.consignment_agents_id,
                "consignment_history": sim.consignment_history,
                "consignment_teamleader_id": ca.ou[0].lead_agents_id,
                "consignment_timestamp": func.now(),
                "modify_stamp": func.now(),
                "consignments_id": consign.id

            },
            synchronize_session=False
        )
        print "GOT BEFORE COMMIT"
        transaction.savepoint()
    print "THIS IS THE ID ID ID ID ID ID : ", consign.id
我将此函数称为:

if self.store.finalise:
    try:
        store = self.store
        agent = self.agent

        do_consignment_task.delay(store, agent)

        transaction.commit()
        self.check_and_purge()
        return "Consignmnet is being processed"
    except Exception, exc:
        self.check_and_purge()
        self.log.exception(exc)
        exc_error = "CONSIGNERR:", exc.message
        raise USSDFailure(exc_error)
else:
    self.store.status = "CANCELLED"
    if "fullconfirm" in self.session:
        del self.session["fullconfirm"]
    self.check_and_purge()
    return "CONSIGNMENT Cancelled"
当我运行此代码时,出现以下错误:

EncodeError: Can't pickle <class 'pyramid.util.Request'>: attribute lookup pyramid.util.Request failed
以及:


但是,这仍然会给我同样的错误:|

请尝试不要序列化金字塔请求对象。当你与芹菜任务互动时,你应该把它看作一个独立的过程

为它提供工作所需的所有信息。请注意,您需要序列化该信息

因此self.store可能包含属性引用,序列化这些引用可能不现实

也许在store对象上创建一个方法,返回一个干净的dictionary对象

def serialize(self):
    data = {}
    data["element1"] = self.element1
    data["element2"] = self.element2
    data["element3"] = self.element3
    return data

然后,当您要调用delay方法时,请确保使用store.serialize()而不是store或dict

谢谢,我会尝试使用它<代码>:)
if self.store.finalise:
    try:
        # del self.service
        store = self.store.__dict__.copy()
        agent_id = self.agent.id
        print store
        print agent_id
        # print help(store)
        do_consignment_task.delay(agent_id, **store)
        transaction.commit()
        #etc
def serialize(self):
    data = {}
    data["element1"] = self.element1
    data["element2"] = self.element2
    data["element3"] = self.element3
    return data