views:

193

answers:

2

I'm using suds https://fedorahosted.org/suds/ to fetch data using SOAP. I'd like to cache the result (using memcached) to not overload the server from where I'm fetching the data. The problem is when fetching the cached data. Fetching it works fine but then django tries to decode the data (force_unicode) and it fails with the following:

The string that could not be encoded/decoded was:  armv�rmare t

This is what I use to cache the result (where result = suds-object). Using cPickle (and tried pickle just in case but without success, no surprise).

The suds response is in unicode.

#Cache the result 
cache.set(hashstring, pickle.dumps(result), 120) 
#Return the cached data
result = cache.get(hashstring) 
if result: 
    return pickle.loads(result, encoding='utf-8')
A: 

Are you positive that memcached supports storage of complex objects?

Another thing to consider is that SUDS has its own caching mechanism built-in, but I believe it is only for the WSDL/XSD data, so that it doesn't have to be recompiled every time you startup. I am not totally positive, however, and it's possible that it could also be used for storage of results.

jathanism
I'm not sure memcached supports it but I've also tried to store to a file with pickle and I get problems there as well.
xintron
A: 

Suds returns a suds.sax.text.Text object, which is a subclass of the Python Unicode string object. I think explicitly casting that object to Unicode would solve your problem.

#Cache the result 
cache.set(hashstring, unicode(result), 120) 
#Return the cached data
result = cache.get(hashstring) 
if result:
    return result
mikl