File upload using httplib

alastair ally_burnett at
Mon Jul 26 09:14:49 EDT 2004


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

At the moment I can test out sending a set of parameters to the
server, and using mod_python, I have a python script which displays
these values.

I'm no expert when it comes to the http standard so I'm not sure if
using httplib is the right way to go about things. If anyone has any
advice on how to go about this, I'd appreciate it.

Here's the code I've used to initiate a 'POST' to the server (straight
out of the Python documentation):

import httplib, urllib

params = urllib.urlencode({'spam': 1, 'eggs': 2})

headers = {"Content-type": "application/x-www-form-urlencoded",
           "Accept": "text/plain"}

conn = httplib.HTTPConnection("")
conn.request("POST", "/test/")
response = conn.getresponse()

print response.status, response.reason

data =



More information about the Python-list mailing list