<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix"><br>
Hi,<br>
<br>
First, please update to the latest version of Spyne.<br>
<br>
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.<br>
<br>
By the way, Spyne's MTOM code is not working (doesn't even have
tests). Patches are welcome :)<br>
<br>
Best,<br>
Burak<br>
<br>
On 12/17/12 11:16, Gopalakrishna Bhat wrote:<br>
</div>
<blockquote
cite="mid:CADqpWhhVcf6fChoWbO9vBvT-Hhi9C_MWZj9VJuG0Pdrs4s--gA@mail.gmail.com"
type="cite">
<div>Hi all,</div>
<div><br>
</div>
<div>I am trying to use spyne to build a service that uploads a
file. Following the example at</div>
<div><a moz-do-not-send="true"
href="https://github.com/arskom/spyne/tree/master/examples/file_manager">https://github.com/arskom/spyne/tree/master/examples/file_manager</a>
I have the following code</div>
<div><br>
</div>
<div>class MyService(ServiceBase):</div>
<div><span class="" style="white-space:pre"> </span>@rpc(Unicode,
Unicode, spyne.model.binary.File.customize(min_occurs=1,
nullable=False), _returns=Unicode)</div>
<div>
<span class="" style="white-space:pre"> </span>def add(ctx,
person_type, action, file):</div>
<div><span class="" style="white-space:pre"> </span>try:</div>
<div><span class="" style="white-space:pre"> </span>os.makedirs('./files')</div>
<div><span class="" style="white-space:pre"> </span>except
OSError:</div>
<div><span class="" style="white-space:pre"> </span>pass</div>
<div><span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span><a
moz-do-not-send="true" href="http://log.info">log.info</a>("Person
Type: %r" % person_type)</div>
<div><span class="" style="white-space:pre"> </span><a
moz-do-not-send="true" href="http://log.info">log.info</a>("Action:
%r" % action)</div>
<div><span class="" style="white-space:pre"> </span>os.path.abspath('./files')</div>
<div><span class="" style="white-space:pre"> </span>path =
os.path.join(os.path.abspath('./files'), <a
moz-do-not-send="true" href="http://file.name">file.name</a>)</div>
<div><span class="" style="white-space:pre"> </span><a
moz-do-not-send="true" href="http://log.info">log.info</a>("Path:
%r" % <a moz-do-not-send="true" href="http://file.name">file.name</a>)</div>
<div><span class="" style="white-space:pre"> </span>if not
path.startswith(os.path.abspath('./files')):</div>
<div><span class="" style="white-space:pre"> </span>raise
ValidationError(<a moz-do-not-send="true"
href="http://file.name">file.name</a>)</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>f =
open(path, 'w') # if this fails, the client will see an</div>
<div> # # internal error.</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>try:</div>
<div><span class="" style="white-space:pre"> </span>for data in
file.data:</div>
<div><span class="" style="white-space:pre"> </span>f.write(data)</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>log.debug("File
written: %r" % <a moz-do-not-send="true"
href="http://file.name">file.name</a>)</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>f.close()</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>except:</div>
<div><span class="" style="white-space:pre"> </span>f.close()</div>
<div><span class="" style="white-space:pre"> </span>os.remove(<a
moz-do-not-send="true" href="http://file.name">file.name</a>)</div>
<div><span class="" style="white-space:pre"> </span>log.debug("File
removed: %r" % <a moz-do-not-send="true"
href="http://file.name">file.name</a>)</div>
<div><span class="" style="white-space:pre"> </span>raise #
again, the client will see an internal error.</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>return "gk."</div>
<div><span class="" style="white-space:pre"> </span></div>
<div>services =
csrf_exempt(DjangoApplication(Application([MyService],</div>
<div> 'services',</div>
<div> in_protocol=Soap11(),</div>
<div> out_protocol=Soap11(),</div>
<div> )))</div>
<div><span class="" style="white-space:pre"> </span></div>
<div>I am accessing the service via C# .NET and on the server side
I get this exception</div>
<div>[17/Dec/2012 14:03:14] ERROR [spyne.application:137]
'NoneType' object has no attribute 'name'</div>
<div>Traceback (most recent call last):</div>
<div> File
"C:\Python27\lib\site-packages\spyne-2.8.0_rc-py2.7.egg\spyne\application.py",
line 109, in process_request</div>
<div> ctx.out_object = self.call_wrapper(ctx)</div>
<div> File
"C:\Python27\lib\site-packages\spyne-2.8.0_rc-py2.7.egg\spyne\application.py",
line 153, in call_wrapper</div>
<div> return ctx.service_class.call_wrapper(ctx)</div>
<div> File
"C:\Python27\lib\site-packages\spyne-2.8.0_rc-py2.7.egg\spyne\service.py",
line 198, in call_wrapper</div>
<div> return ctx.function(ctx, *ctx.in_object)</div>
<div> File
"D:\DevWorks\SupporTrac\SupporTrac\SupporTrac\SupporTracWebApp\views.py",
line 362, in add</div>
<div> path = os.path.join(os.path.abspath('./files'), <a
moz-do-not-send="true" href="http://file.name">file.name</a>)</div>
<div>AttributeError: 'NoneType' object has no attribute 'name'</div>
<div><br>
</div>
<div>Can anyone point me as to what am I doing wrongly?</div>
<div><br>
</div>
<div>BTW basic service without attachments are working fine</div>
<div><br>
</div>
<div>-Gopal</div>
<div><br>
</div>
-- <br>
My blog <a moz-do-not-send="true"
href="http://gkbhat.blogspot.com">http://gkbhat.blogspot.com</a><br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Soap mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Soap@python.org">Soap@python.org</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/soap">http://mail.python.org/mailman/listinfo/soap</a>
</pre>
</blockquote>
<br>
</body>
</html>