I finished making a basic web server a little while ago, however I cannot access it at all. I ran it on my mac, which didn't work. I then ran it on my PC and tried to access it from my mac using Firefox.

This is the code I have for the server:

from http.server import HTTPServer, BaseHTTPRequestHandler

class RequestHandler(BaseHTTPRequestHandler):
    def _writeheaders(self):
        self.send_header('Content-type', 'text/html')

    def do_HEAD(self):

    def do_GET(self):
<HEAD><TITLE>Sample title</TITLE></HEAD>
<BODY>sample text</BODY>

serveraddr = ('', 8080)
srvr = HTTPServer(serveraddr, RequestHandler)

print("Server online and active")


Here's the error I got from Firefox:

Failed to Connect

Firefox can't establish a connection to the server at ##.#.#.#:8080.
Though the site seems valid, the browser was unable to establish a connection.

* Could the site be temporarily unavailable? Try again later.
* Are you unable to browse other sites? Check the computer's network connection.
* Is your computer or network protected by a firewall or proxy? Incorrect settings can interfere with Web browsing

and here's what I got with safari:

Safari can’t connect to the server.
Safari can’t open the page “http://##.#.#.#:8080/” because it could not connect to the server “##.#.#.#”.

How would I make this accessible remotely?


I have never used a Python web server...So I wudnt know whether this works or not...

I will have to check this code in my home....

Are you able to access the page on the same box?



Does it work?? If it does, then could be something between the machines.....or other problems which needs to be looked into...

I tried both, neither worked. :(

What is the version of Python you use?

I tried both, neither worked. :(

If they're not working on the system where the server is running then your code is flawed. There was just a thread about this a few days ago that had a working server... Look there and try out that code.

Ok... here goes... I tried ur code at my home Vista.
The only change I needed to make was

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer

instead of

from http.server import HTTPServer, BaseHTTPRequestHandler

Mine is 2.6, so I think it needed the change.
When I ran ur code, vista prompted me to allow the port 8080, for which I did.

Wallah!!! I see "sample text" in the web page when I use http://localhost:8080

I tried to access the vista machine with its IP from a different machine(Linux machine)... it worked again...

So I think u should check ur firewalls. I dont know about Mac, so that would be ur area to explore....