I put a print statement at the end to make sure that the whole script was executed. It was not.
Did you put a print statement after serve_forever() ? I'm pretty sure that forever indicates a super loop (ie, while True: )
jlm699
Veteran Poster
1,112 posts since Jul 2008
Reputation Points: 355
Solved Threads: 292
What about accessing it remotely from a different computer?
Same as above but instead of localhost use the ip address of the computer where the server is running.
jlm699
Veteran Poster
1,112 posts since Jul 2008
Reputation Points: 355
Solved Threads: 292
Why don't you try sending something simpler... this is an example i found from googling:
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write("Hello World!")
jlm699
Veteran Poster
1,112 posts since Jul 2008
Reputation Points: 355
Solved Threads: 292
That's strange. I just tried your code out and it worked with no problem. The only change I made was for the imports since I'm running it with py2.5
Here's what I ran:
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
class RequestHandler(BaseHTTPRequestHandler):
def _writeheaders(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_HEAD(self):
self._writeheaders()
def do_GET(self):
self._writeheaders()
self.wfile.write("""<HTML>
<HEAD><TITLE>Sample title</TITLE></HEAD>
<BODY>sample text</BODY>
</HTML>""")
serveraddr = ('', 8080)
srvr = HTTPServer(serveraddr, RequestHandler)
srvr.serve_forever()
Then going to localhost:8080 in my browser resulted in a page with sample text
jlm699
Veteran Poster
1,112 posts since Jul 2008
Reputation Points: 355
Solved Threads: 292