XML-RPC -- send file

C

codecraig

Hi,
I want to use XML-RPC to send a file from client-to-server or from
server-to-client. I know XML-RPC supports, int, string etc...not
objects.

I thought i read somewhere that by using pickle or something, that u
could get a string representation of your object (or a file in my case)
and send that. Any ideas?

thanks.
 
S

Skip Montanaro

codecraig> I thought i read somewhere that by using pickle or something,
codecraig> that u could get a string representation of your object (or a
codecraig> file in my case) and send that. Any ideas?

Sure:

stuff = xmlrpclib.Binary(open(somefile).read())
server.call_some_remote_function(stuff)

At the other end a similar decoding will have to be done.

Skip
 
S

Skip Montanaro

codecraig> how would I decode it?

Assuming you have Python at the other end and you get a Binary object
instead of a string, access its data attribute. OTOH, xmlrpclib may
automatically decode the wrapper object for you.

In any case, I have two further recommendations:

* Check the xmlrpclib docs.

* Experiment. Electrons are hardy fellows and hardly ever break at the
energy levels present in modern computers.

Skip
 
C

codecraig

Experient I have been :)

Here is what I am getting now....

CLIENT
-----------
d = xmlrpclib.Binary(open("C:\\somefile.exe").read())
server.sendFile(d)

SERVER
--------------
def sendFile(tmp):
print "FILE:", tmp

The server receives the file, because it prints it out, but on the
client I get this....

xmlrpclib.Fault: <Fault 1: 'exceptions.TypeError:cannot marshal None
unless allow_none is enabled'>

so it sends it, but the client is getting an error. The error occurs
on the, server.sendFile(d) line.

any ideas?
 
S

Stefan Behnel

codecraig said:
CLIENT
-----------
d = xmlrpclib.Binary(open("C:\\somefile.exe").read())
server.sendFile(d)

SERVER

This returns None. Don't know what XML-RPC expects, but you may either try
to return something else from the function or make XML-RPC return nothing
(don't know if that works).
xmlrpclib.Fault: <Fault 1: 'exceptions.TypeError:cannot marshal None
unless allow_none is enabled'>

The obvious error. :)

Stefan
 
F

F. Petitjean

Le 19 Apr 2005 11:02:47 -0700, codecraig a écrit :
Experient I have been :)

Here is what I am getting now....

CLIENT
open the file with mode "rb"
fin = open(r'C:\somefile.exe', 'rb')
contents = fin.read()
fin.close()
d = xmlrpclib.Binary(contents)
 
C

codecraig

stefan: i added, "return 1" to my sendFile method on the server...took
care of the error, thanks.

f. petitjean: i cleaned up my code by closing the file, however, when i
tried your exact code above...i got stuck an infinite loop and my PC
speaker beeped over and over :)

thanks.
 
S

Skip Montanaro

codecraig> stefan: i added, "return 1" to my sendFile method on the server...took
codecraig> care of the error, thanks.

Yes, by default XML-RPC doesn't support objects like Python's None. As the
error message indicated you have to enable allow_none to permit transmission
of None.

Skip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,236
Messages
2,571,182
Members
47,818
Latest member
KazukoXea6

Latest Threads

Top