pbienst wrote: > I would like to bundle up a number of files in a tar file and send it > over a HTTP connection, but I would like to do this without creating > the tar file on disk first. > > I know I can get tarfile to output to a stream by doing something like > > tar_pipe = tarfile.open(mode="w|", fileobj=my_file_obj) > > However, I can't figure out which file object to use to send this over > a HTTP connection. > > I tried > > conn = httplib.HTTPConnection(hostname, port) > conn.putrequest("PUT", "/client/files") > conn.endheaders() > tar_pipe = tarfile.open(mode="w|", fileobj=conn.sock.makefile()) > for filename in filenames: > tar_pipe.add(filename) > tar_pipe.close() > conn.getresponse() > > but that does not send any data... > I haven't used socket.makefile() in a blue age so this is untested, but I'm guessing you need a *write* file (remember, sockets have two directions). So try
.... fileobj=conn.sock.makefile("w")... and let me know if that helps. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list