gethostname() returns accurate hostname, bind() doesn't like it
Posted
by
user2072848
on Stack Overflow
See other posts from Stack Overflow
or by user2072848
Published on 2014-06-12T21:21:15Z
Indexed on
2014/06/12
21:24 UTC
Read the original article
Hit count: 442
python
|socketserver
Doing a python socket tutorial, entire codebase is as follows
import socket as so
s = so.socket()
host = so.gethostname()
port = 12345
s.bind((host, port))
s.listen(5)
while True:
c, addr = s.accept()
print 'Got connection from', addr
c.send('Thank you for connecting')
c.close()
and error message:
Traceback (most recent call last):
File "server.py", line 13, in <module>
s.bind((host, port))
File "/Users/solid*name*/anaconda/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Printing hostname gives me
super*name*
Which is, in fact, my computer's hostname.
© Stack Overflow or respective owner