title: Python 3.x BaseHTTPServer or http.server
body: <p>I am trying to make a BaseHTTPServer program. I prefer to use Python 3.3 or 3.2 for it. I find the doc hard to understand regarding what to import but tried changing the import from:</p>
  
  <pre><code>from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>from http.server import BaseHTTPRequestHandler,HTTPServer
  </code></pre>
  
  <p>and then the import works and the program start and awaits a GET request. BUT when the request arrives an exception is raised:</p>
  
  <pre><code>File "C:\Python33\lib\socket.py", line 317, in write return self._sock.send(b)
  TypeError: 'str' does not support the buffer interface
  </code></pre>
  
  <p>Question: Is there a version of BaseHTTPServer or http.server that works out of the box with Python3.x or am I doing something wrong?</p>
  
  <p>This is "my" program that I try running in Python 3.3 and 3.2:</p>
  
  <pre><code>#!/usr/bin/python
  # from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
  from http.server import BaseHTTPRequestHandler,HTTPServer
  
  PORT_NUMBER = 8080
  
  # This class will handle any incoming request from
  # a browser 
  class myHandler(BaseHTTPRequestHandler):
  
      # Handler for the GET requests
      def do_GET(self):
          print   ('Get request received')
          self.send_response(200)
          self.send_header('Content-type','text/html')
          self.end_headers()
          # Send the html message
          self.wfile.write("Hello World !")
          return
  
  try:
      # Create a web server and define the handler to manage the
      # incoming request
      server = HTTPServer(('', PORT_NUMBER), myHandler)
      print ('Started httpserver on port ' , PORT_NUMBER)
  
      # Wait forever for incoming http requests
      server.serve_forever()
  
  except KeyboardInterrupt:
      print ('^C received, shutting down the web server')
      server.socket.close()
  </code></pre>
  
  <p>The Program work partly in Python2.7 but gives this exception after 2-8 requests:</p>
  
  <pre><code>error: [Errno 10054] An existing connection was forcibly closed by the remote host
  </code></pre>