It's atrocious that the standard httplib doesn't support this (see
http://bugs.python.org/issue3244). However, there's a good recipe for
doing this at
http://code.activestate.com/recipes/146306/, which I've
used for years. It's also possible to do this using the
email.message.Message class, though you have to add the Content-
Disposition headers explicitly, something like this:
m = email.message.Message()
m.add_header("Content-Type", "multipart/form-data")
for (name, value_type, value) in items:
part = email.message.Message()
part.add_header("Content-Type", value_type)
part.add_header("Content-Disposition", 'form-data; name="%s"' %
name)
part.set_payload(value)
m.attach(part)
body = m.as_string()
Bill