Python Forum
socket.gaierror: [Errno -2] Name or Service not known
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
socket.gaierror: [Errno -2] Name or Service not known
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  socket.gaierror: [Errno 11001] Johnygo 4 10,709 Nov-03-2019, 08:52 PM
Last Post: nemat
  socket.gaierror: [Errno -2] Name or service not known seokangwoo99 5 15,650 May-25-2019, 02:36 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020