def post_multipart(host, selector, fields, files): """Post fields and files to an http host as multipart/form-data. fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return the server's response page. """ content_type, body = encode_multipart_formdata(fields, files) h = httplib.HTTP(host) h.putrequest("POST", selector) h.putheader("content-type", content_type) h.putheader("content-length", str(len(body))) h.endheaders() h.send(body) errcode, errmsg, headers = h.getreply() return h.file.read()