En Sat, 19 Jan 2008 21:19:24 -0200, Wolfgang Draxinger <[EMAIL PROTECTED]> escribi�:
> I'm thinking about writing a script to upload videos to sites > like YouTube or Google Video, which is usually done by a HTTP > POST. > > The problem is, that videos, by nature are rather big files, > however urllib2 wants it's Request objects being prepared > beforehand, which would mean to first load the whole file to > memory. > > I looked into pycURL, knowing that cURL can POST send files > directily from the file system, however pycURL doesn't expose > the neccesary functions yet. > > Am I just blind for some urllib2/httplib feature, or some other > library? Or do I really have to fiddle around with sockets > myself (I hope not...). I'm afraid urllib2 currently doesn't handle this. Neither the lower layer, httplib. HTTPConnection should be upgraded to handle 'Transfer-Encoding: chunked', by example. (Chunked responses are handled correctly, but a request cannot be chunked) A Q&D approach would be to patch httplib.HTTPConnection.send, to accept a file or file-like argument. Around line 707, instead of self.sock.sendall(str): if hasattr(str, 'read'): BUFSIZE = 4*1024 while True: block = str.read(BUFSIZE) if not block: break self.sock.sendall(block) else: self.sock.sendall(str) and ensure the Content-Length header is already set, so no attempt is made to compute len(str) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list