By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,524 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,524 IT Pros & Developers. It's quick & easy.

XML-RPC -- send file

P: n/a
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.

Jul 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

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
Jul 19 '05 #2

P: n/a
how would I decode it?

Jul 19 '05 #3

P: n/a

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
Jul 19 '05 #4

P: n/a
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?

Jul 19 '05 #5

P: n/a

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

SERVER
--------------
def sendFile(tmp):
print "FILE:", tmp
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
Jul 19 '05 #6

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

Here is what I am getting now....

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

any ideas?

Jul 19 '05 #7

P: n/a
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.

Jul 19 '05 #8

P: n/a

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
Jul 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.