[Tutor] Socket Module
Alan Gauld
alan.gauld at btinternet.com
Mon Jul 13 08:58:45 CEST 2015
On 12/07/15 23:36, Nym City via Tutor wrote:
> import csv
> import socket
>
> domains = open('top500domains.csv', 'r')
> for domain in domains:
> domain = socket.gethostbyname(str(domains))
You are passing your file object to gethostbyname()
> print(domains + "\n")
> For the code above, I receive the following error on run: socket.gaierror: [Errno -2] Name or service not known.
> Variation 2:
> import csv
> import socketdomains = []
I assume the domains bit is on a separate line?
>
> with open('top500domains.csv', 'r') as f:
> for line in f:
> line = line.strip()
> domains.append(line)
>
> hostbyname_ex = socket.gethostbyname_ex(str(domains))
Again you are passing the entire list to gethostbyname_ex()
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list