multipart/form-data in an HTTP client

John J. Lee jjl at pobox.com
Wed Sep 1 13:39:12 EDT 2004


Nelson Minar <nelson at monkey.org> writes:

> I'm writing some code to upload photos to Flickr. The Photo Upload API
> requires documents be POSTed via a multipart/form-data request. I was
> surprised to learn that Python 2.3's HTTP clients don't support this
> form of POSTs. There is support in cgi.py, for servers.

"Not supported" is an exaggeration, perhaps: there isn't special
support to make it especially easy, true, but neither is there
anything about urllib2 that makes it harder than it should be given
the level of the interface exposed: you just have to add the right
HTTP headers and HTTP request body data.


> There are some implementations of multipart/form-data on ASPN:
>   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306
> urllib2_file seems to meet my needs, but I'm not wild about how it's
> implemented.

What's wrong with that implementation?  Looks reasonable to me, though
it seems to have a hack to work around bad servers that is different to
the one I have in my own code.  I can well believe that both hacks are
required to work with as many servers as possible :-(


John



More information about the Python-list mailing list