[Soap-Python] Attachments as soap request

Burak Arslan burak.arslan at arskom.com.tr
Mon Dec 17 10:52:15 CET 2012


Hi,

First, please update to the latest version of Spyne.

I did not add support for the File type to Soap as the Xml Schema 
standard doesn't have a File primitive. You can have binary data sent 
into Spyne code via SOAP using the ByteArray (==base64binary) type.

By the way, Spyne's MTOM code is not working (doesn't even have tests). 
Patches are welcome :)

Best,
Burak

On 12/17/12 11:16, Gopalakrishna Bhat wrote:
> 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 <http://log.info>("Person Type: %r" % person_type)
> log.info <http://log.info>("Action: %r" % action)
> os.path.abspath('./files')
> path = os.path.join(os.path.abspath('./files'), file.name 
> <http://file.name>)
> log.info <http://log.info>("Path: %r" % file.name <http://file.name>)
> if not path.startswith(os.path.abspath('./files')):
> raise ValidationError(file.name <http://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 <http://file.name>)
>
> f.close()
>
> except:
> f.close()
> os.remove(file.name <http://file.name>)
> log.debug("File removed: %r" % file.name <http://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 
> <http://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
>
>
> _______________________________________________
> Soap mailing list
> Soap at python.org
> http://mail.python.org/mailman/listinfo/soap

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/soap/attachments/20121217/3493c2e1/attachment.html>


More information about the Soap mailing list