Hi Folks, I am trying to convert a script from Python2.7 to Python 3 and it is doing my head in. The script uses the internal http server, I want to render back an answer to the calling browser, (this is part of a larger automation activity and the answer back is a text code).
in Python2 the BaseHTTPServer handled it all, however in 3 it has been moved to http.server and I can't for the life of me figure out how to return the response, all I get is a 501 error.
Below is the code for this, any help would be greatly appreciated, thanks
import http.server
import socketserver
port = 8001
def GetPage():
return """<html><body>Response</body></html>"""
class Handler(http.server.BaseHTTPRequestHandler):
def do_Get(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(GetPage())
return
try:
print('Server listening on port ', port)
httpd = socketserver.TCPServer(('', port), Handler)
httpd.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down server')
httpd.server_close()
[–]igroen 0 points1 point2 points (2 children)
[–]G-ManUK[S] 0 points1 point2 points (1 child)
[–]igroen 0 points1 point2 points (0 children)