XML-RPC -- send file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • codecraig

    XML-RPC -- send file

    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.

  • Skip Montanaro

    #2
    Re: XML-RPC -- send file


    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.Binar y(open(somefile ).read())
    server.call_som e_remote_functi on(stuff)

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

    Skip


    Comment

    • codecraig

      #3
      Re: XML-RPC -- send file

      how would I decode it?

      Comment

      • Skip Montanaro

        #4
        Re: XML-RPC -- send file


        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

        Comment

        • codecraig

          #5
          Re: XML-RPC -- send file

          Experient I have been :)

          Here is what I am getting now....

          CLIENT
          -----------
          d = xmlrpclib.Binar y(open("C:\\som efile.exe").rea d())
          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.Typ eError: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?

          Comment

          • Stefan Behnel

            #6
            Re: XML-RPC -- send file


            codecraig schrieb:[color=blue]
            > CLIENT
            > -----------
            > d = xmlrpclib.Binar y(open("C:\\som efile.exe").rea d())
            > server.sendFile (d)
            >
            > SERVER
            > --------------
            > def sendFile(tmp):
            > print "FILE:", tmp[/color]

            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).
            [color=blue]
            > xmlrpclib.Fault : <Fault 1: 'exceptions.Typ eError:cannot marshal None
            > unless allow_none is enabled'>[/color]

            The obvious error. :)

            Stefan

            Comment

            • F. Petitjean

              #7
              Re: XML-RPC -- send file

              Le 19 Apr 2005 11:02:47 -0700, codecraig a écrit :[color=blue]
              > Experient I have been :)
              >
              > Here is what I am getting now....
              >
              > CLIENT
              > -----------
              > d = xmlrpclib.Binar y(open("C:\\som efile.exe").rea d())[/color]
              open the file with mode "rb"
              fin = open(r'C:\somef ile.exe', 'rb')
              contents = fin.read()
              fin.close()
              d = xmlrpclib.Binar y(contents)
              [color=blue]
              > server.sendFile (d)
              >
              > any ideas?
              >[/color]

              Comment

              • codecraig

                #8
                Re: XML-RPC -- send file

                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.

                Comment

                • Skip Montanaro

                  #9
                  Re: XML-RPC -- send file


                  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

                  Comment

                  Working...