Python Forum

Full Version: socket.gaierror: [Errno -2] Name or Service not known
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, so I'm using Python 3.4 and currently I'm trying to get this code that I found to work. So what I want to do is log some information / access it from another location. So this is the code that I'm currently using:

#!/usr/bin/python3.4
import socketserver
import http.server

class HTTPHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == "/admin":
self.wfile.write("This Page is For Admins Only!!\n")
self.wfile.write(self.headers)
else:
http.server.SimpleHTTPRequestHandler.do_GET(self)

http_Server = socketserver.TCPServer((" ", 4444), HTTPHandler)
http_Server.server_forever()

But it gives me this error:
socket.gaierror: [Errno -2] Name or Service not known

Can someone explain to me what this error means and how I can fix this issue?
Thanks Big Grin
http_Server = socketserver.TCPServer((" ", 4444), HTTPHandler)
That empty string is your problem. You need to give the server a hostname or interface for it to "listen" for incoming connections. If you are doing all of this local to your computer, you can specify "localhost" or "127.0.0.1", if you want to access it from another computer, you can specify "0.0.0.0" which means accept connections on any network interface.