File upload using httplib

John J. Lee jjl at
Mon Jul 26 22:31:42 CEST 2004

ally_burnett at (alastair) writes:

> I'm attempting to test out some functionality of the Apache http
> server. What I'd like to do is send a file to the server - eg. a text
> file or binary file (I will be testing gzipped transfers eventually
> ...).

This is called 'HTTP file upload'.  Use Google Groups to see lots of
posts about it in this newsgroup.  Eg:

If you haven't done already, install a sniffer or a proxy.  Ethereal
works for me.

> headers = {"Content-type": "application/x-www-form-urlencoded",
>            "Accept": "text/plain"}
> conn = httplib.HTTPConnection("")
> conn.request("POST", "/test/")

As Peter said, you're failing to send the headers you think you are.

If you did send those headers, though, you would be asking the server
to believe you're POSTing application/x-www-form-urlencoded data
(stuff like foo=bar&spam=eggs), but sending it a Python file.


More information about the Python-list mailing list