File upload using httplib

John J. Lee jjl at pobox.com
Mon Jul 26 16:31:42 EDT 2004


ally_burnett at yahoo.co.uk (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:

http://groups.google.com/groups?&threadm=10fojr85tvg4i28%40corp.supernews.com

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("127.0.0.1:8080")
> conn.request("POST", "/test/test.py")
[...]

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.


John



More information about the Python-list mailing list