Simple example of BaseHTTPServer use

David Lees DavidLNoSpam at raqia.com
Thu Jun 14 19:00:59 EDT 2001


I have his example on page 198 in front of me.  But I am puzzled,
because the http headers need a line:
'Content-length: (number of bytes in content goes here)', but when I
execute an end_headers() before generating content into wfile, how can
the correct value go into Content-length?  In fact is 'Content-length'
even being generated?

david lees


Doug Fort wrote:
> 
> David Lees wrote:
> 
> > I would like to use the BaseHTTPServer class to handle a PUT  and send
> > back some http.  I am sending the headers back correctly I think, but no
> > data appears to be going back.  I am probably using the wfile instance
> > variable incorrectly.  Here is sample code I am working on.
> >
> > def do_PUT(self):
> >         self.send_response(200,'<response></response>\n')
> >         self.send_header("Content-type", "text/html")
> >         self.wfile.write('junker goes\nout here\n')
> >         self.end_headers()
> >
> >
> >
> > Thanks in advance.
> >
> > David Lees
> >
> I believe you need to call end_headers() before attempting to send any
> data.  end_headers() writes a blank line which is followed by the data.  I
> recommend Frederik Lundh's book "Python Standard Library" from O'Reilly, it
> has good clear examples and list lists at US$29.95 unlike the bloated $50
> books that line the shelves.
> 
> --
> Doug Fort <dougfort at downright.com>
> Senior Meat Manager
> Downright Software LLC
> http://www.downright.com
> 
> ______________________________________________________________________
> Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
>    With Seven Servers In California And Texas - The Worlds Uncensored News Source
>



More information about the Python-list mailing list