publishers_20.py 667 B

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