Python http upload script

Posted on May 15, 2009. Filed under: Python |

Python http upload script

 Httplib module and some useful methods

 Note   The httplib module has been renamed to http.client in Python 3.0. The 2to3 tool will automatically adapt imports when converting your sources to 3.0.

class httplib.HTTPConnection(host[, port[, strict[, timeout]]])

 HTTPConnection.request(method, url[, body[, headers]])


Note   Note that you must have read the whole response before you can send a new request to the server


Set the debugging level (the amount of debugging output printed). The default debug level is 0, meaning no debugging output is printed.


Connect to the server specified when the object was created.


Close the connection to the server.

As an alternative to using the request() method described above, you can also send your request step by step, by using the four functions below.

HTTPConnection.putrequest(request, selector[, skip_host[, skip_accept_encoding]])

This should be the first call after the connection to the server has been made. It sends a line to the server consisting of the request string, the selector string, and the HTTP version (HTTP/1.1). To disable automatic sending of Host: or Accept-Encoding: headers (for example to accept additional content encodings), specify skip_host or skip_accept_encoding with non-False values.

Changed in version 2.4: skip_accept_encoding argument added.

HTTPConnection.putheader(header, argument[, ])

Send an RFC 822-style header to the server. It sends a line to the server consisting of the header, a colon and a space, and the first argument. If more arguments are given, continuation lines are sent, each consisting of a tab and an argument.


Send a blank line to the server, signalling the end of the headers.


Send data to the server. This should be used directly only after the endheaders() method has been called and before getresponse() is called.


 Example of upload file by PUT

 import httplib

conn = httplib.HTTPConnection(“”)



conn.putheader(“Content-Length”, “32”)


conn.send(“Hello world, I am uploading 32 bytes, if the length is less than 32 bytes, the script will halt here, if more than 32 bytes, the upload.php will only read the first 32 bytes”)

resps = conn.getresponse()

data =

print “response is the webpage which upload.php shows after PUT upload:”, data



httplib — HTTP protocol client

 urllib — Open arbitrary resources by URL

Http client to POST using multipart/form-data

Big File Upload

httplib HTTPConnection request problem

PyCURL interface – Uploading large binary files


HTTP Upload — An Overview

HTTP Upload using a Proxy Server

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: