Kumakaja Kumakaja - 13 days ago 4
HTTP Question

BaseHTTPServer.HTTPServer isn't visible from the Internet

I'm running a Python server on a remote server:

server_class = BaseHTTPServer.HTTPServer
httpd = server_class(("127.0.0.1", 80), MyHandler)
httpd.serve_forever()
httpd.server_close()


From a server, I can make a query: "curl -i localhost" and it works fine. However, from a remote computer I can't, even though there's no firewall.

curl: (7) Failed to connect to aa.bb.cc.dd port 80: Connection refused


I'm trying to do that by the ip address of a server.

Answer

Of course you cannot. You bind you server to the 127.0.0.1 local only address, so it can only answer local queries. Use the special 0.0.0.0 address to allow it to answer on any interfaces:

httpd = server_class(("0.0.0.0", 80), MyHandler)
Comments