1

The following code works fine with python.exe but fails with pythonw.exe. I'm using Python 3.1 on Windows 7.

from http.server import BaseHTTPRequestHandler, HTTPServer

class FooHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        length = int(self.headers['Content-Length'])
        data = self.rfile.read(length)
        print(data)
        self.send_response(200)
        self.send_header('Content-Length', '0')
        self.end_headers()

httpd = HTTPServer(('localhost', 8000), FooHandler)
httpd.serve_forever()

Something wrong when I start sending responses. Nothing got written back. And if I try another http connection it won't connect. I also tried using self.wfile but no luck either.

llc
  • 129
  • 9

1 Answers1

1

You are printing to stdout. pythonw.exe doens't have a stdout, as it's not connected to a terminal. My guess is that this has something to do with it.

Try to redirect stdout to a file, or quicker, remove the print().

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • thanks. I redirected sys.stdout and sys.stderr to open(os.devnull, 'w') and it's running smoothly. – llc Feb 25 '11 at 13:30