views:

75

answers:

2

Very simple.

>>> import socket
>>> socket.gethostbyname('http://yahoo.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
+11  A: 

Very simple.

"http://yahoo.com" is not a host name. Try socket.gethostbyname('yahoo.com') :)

Magnus Hoff
A: 

It is because, quite frankly, http://yahoo.com is in no way a domain name, which gethostbyname expects from you. http://yahoo.com is an URL.

>>> import socket
>>> socket.gethostbyname("yahoo.com")
'69.147.114.224'
shylent
"in no way" is not really correct. </nitpicking>
jae
how is it not really correct? you mean "in no way" is not grammatically correct? :P In that case, I apologize. Otherwise, `http://yahoo.com` is *not* a valid domain name at all.
shylent