为了避免在开发过程中反复访问SOAP服务器,我尝试缓存结果,以便在不每次查询服务器的情况下运行我的其余代码。
使用下面的代码时,当我尝试对suds结果进行 pickling 时,会出现 "PicklingError: Can't pickle <class suds.sudsobject.AdvertiserSearchResponse at 0x03424060>: it's not found as suds.sudsobject.AdvertiserSearchResponse"。我猜这是因为类是动态创建的。
如果我从
使用下面的代码时,当我尝试对suds结果进行 pickling 时,会出现 "PicklingError: Can't pickle <class suds.sudsobject.AdvertiserSearchResponse at 0x03424060>: it's not found as suds.sudsobject.AdvertiserSearchResponse"。我猜这是因为类是动态创建的。
import pickle
from suds.client import Client
client = Client(...)
result = client.service.search(...)
file = open('test_pickle.dat', 'wb')
pickle.dump(result, file, -1)
file.close()
如果我从
pickle.dump(result, file, -1)
中删除 -1
协议版本,我会得到不同的错误:TypeError: a class that defines __slots__ without defining __getstate__ cannot be pickled
腌制是正确的做法吗?我能做到吗?有更好的方法吗?