Niks Niks - 1 year ago 107
Python Question

suds: google app engine support

I'm trying to use suds in a python Google App Engine application. This is
the traceback:

client = Client(url)
File "/base/data/home/apps/sandbox/test.349741318547153856/suds/client.py",
line 109, in __init__
options.cache = ObjectCache(days=1)
File "/base/data/home/apps/sandbox/test.349741318547153856/suds/cache.py",
line 141, in __init__
location = os.path.join(tmp(), 'suds')
File "/base/python_runtime/python_dist/lib/python2.5/tempfile.py",
line 45, in PlaceHolder
raise NotImplementedError("Only tempfile.TemporaryFile is
available for use")
NotImplementedError: Only tempfile.TemporaryFile is available for use


I tried changing line 109 at client.py:

options.cache = ObjectCache(days=1)


to:

options.cache = None


And it works now but I'm not sure if that can affect something in the
future.

I really appreciate if anybody can help me here.

Thanks in advance.

Answer Source

You can't write to local files in appengine. Thats why you get that error it's trying to write a cache of processed WSDL to a temporary file. You will have to not cache or provide an alternate cache mechanism. I am using suds on appengine with a very expensive WSDL file, so I hacked the caching to write the cache on the dev server filesystem and then uploaded the cache, with the deployed code.

I cheated - sort of.

def precache_wsdl(wsdl,principal):
    log = logging.getLogger()
    log.setLevel = logging.info
    cache_location = os.path.join(os.path.dirname(__file__),"cache")
    security = Security()
    token = UsernameToken(*principal)
    security.tokens.append(token)
    client = Client(wsdl,cache=FileCache(cache_location))
    client.set_options(wsse=security)

I defined this bit of code in my appengine code. Loaded up the remote command api, ran it locally, prepopulating the cache. Then I amde sure that cach_location was set correctly in my real appengine code. When you run in the remote_api shell you are not running with the same restrictions that server code is. In fact you don't even have to run it under the shell, but I tend to do a lot that way.