How to handle file uploads with http.server

Gabriel Genellina gagsl-py2 at
Wed Mar 17 03:07:42 CET 2010

En Thu, 11 Mar 2010 07:30:24 -0300, Neil Blue <Neil.Blue at>  

> I have a basic http.server instance running (class
> HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and I
> would like to upload files with multipart forms.
> def do_POST(self):
> 	ctype, pdict = cgi.parse_header(self.headers['Content-Type'])
> 	if ctype=='multipart/form-data':
> 		print('parsing...')
> 		query=cgi.parse_multipart(self.rfile, pdict)
> 		print(query)
> However the file never seems to finish being parsed. There are no errors,
> but the call hangs at: query=cgi.parse_multipart(self.rfile, pdict)

This may be related to this bug:

reported last week by Mitchell L. Model in this thread:

Gabriel Genellina

More information about the Python-list mailing list