example the following example shows how the httpconnection class can be used to perform memory-efficient file upload to server using post request--something that is not easily accomplished within the urllib framework import os tryfrom httplib import httpconnection except importerrorfrom http client import httpconnection python python boundary "$python-essential-reference$crlf '\ \ndef upload(addrurlformfieldsfilefields)create the sections for form fields formsections [for name in formfieldssection '--'+boundary'content-dispositionform-dataname="% "name''formfields[nameformsections append(crlf join(section)+crlfcollect information about all of the files to be uploaded fileinfo [(os path getsize(filename)formnamefilenamefor formnamefilename in filefields items()create the http headers for each file filebytes fileheaders [for filesizeformname,filename in fileinfoheaders '--'+boundary'content-dispositionform-dataname="% "filename="% "(formnamefilename)'content-length%dfilesize'fileheaders append(crlf join(headers)+crlffilebytes +filesize closing marker closing "--"+boundary+"--\ \ndetermine the entire length of the request content_size (sum(len(ffor in formsectionssum(len(ffor in fileheadersfilebytes+len(closing)upload it conn httpconnection(*addrconn putrequest("post",urlconn putheader("content-type"'multipart/form-databoundary=%sboundaryconn putheader("content-length"str(content_size)conn endheaders( lib fl ff