[Soap-Python] Attachments as soap request

Gopalakrishna Bhat gopalakbhat at gmail.com
Mon Dec 17 10:16:47 CET 2012


Hi all,

I am trying to use spyne to build a service that uploads a file. Following
the example at
https://github.com/arskom/spyne/tree/master/examples/file_manager I have
the following code

class MyService(ServiceBase):
@rpc(Unicode, Unicode, spyne.model.binary.File.customize(min_occurs=1,
nullable=False), _returns=Unicode)
def add(ctx, person_type, action, file):
try:
os.makedirs('./files')
except OSError:
pass
 log.info("Person Type: %r" % person_type)
log.info("Action: %r" % action)
os.path.abspath('./files')
path = os.path.join(os.path.abspath('./files'), file.name)
log.info("Path: %r" % file.name)
if not path.startswith(os.path.abspath('./files')):
raise ValidationError(file.name)

f = open(path, 'w') # if this fails, the client will see an
                            # # internal error.

try:
for data in file.data:
f.write(data)

log.debug("File written: %r" % file.name)

f.close()

except:
f.close()
os.remove(file.name)
log.debug("File removed: %r" % file.name)
raise # again, the client will see an internal error.

return "gk."
services = csrf_exempt(DjangoApplication(Application([MyService],
        'services',
            in_protocol=Soap11(),
            out_protocol=Soap11(),
    )))
I am accessing the service via C# .NET and on the server side I get this
exception
[17/Dec/2012 14:03:14] ERROR [spyne.application:137] 'NoneType' object has
no attribute 'name'
Traceback (most recent call last):
  File
"C:\Python27\lib\site-packages\spyne-2.8.0_rc-py2.7.egg\spyne\application.py",
line 109, in process_request
    ctx.out_object = self.call_wrapper(ctx)
  File
"C:\Python27\lib\site-packages\spyne-2.8.0_rc-py2.7.egg\spyne\application.py",
line 153, in call_wrapper
    return ctx.service_class.call_wrapper(ctx)
  File
"C:\Python27\lib\site-packages\spyne-2.8.0_rc-py2.7.egg\spyne\service.py",
line 198, in call_wrapper
    return ctx.function(ctx, *ctx.in_object)
  File
"D:\DevWorks\SupporTrac\SupporTrac\SupporTrac\SupporTracWebApp\views.py",
line 362, in add
    path = os.path.join(os.path.abspath('./files'), file.name)
AttributeError: 'NoneType' object has no attribute 'name'

Can anyone point me as to what am I doing wrongly?

BTW basic service without attachments are working fine

-Gopal

-- 
My blog http://gkbhat.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/soap/attachments/20121217/241deff5/attachment.html>


More information about the Soap mailing list