TIMEX
TIMEX

Reputation: 272214

Socket module does not work in my Python

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

Upvotes: 0

Views: 1198

Answers (2)

shylent
shylent

Reputation: 10086

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'

Upvotes: 2

Magnus Hoff
Magnus Hoff

Reputation: 22089

Very simple.

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

Upvotes: 11

Related Questions