I am creating a python script which iterates over a list containing domain names, in most cases it is working well (with package downloaded from https://bitbucket.org/richardpenman/pywhois
), but sometimes i got error saying: Socket Error: [Errno 10054] An existing connection was forcibly closed by the remote host
Can i ignore this error?
My python code is:
import whois
import csv
from datetime import datetime
import sys
import time
def getDomainExpirationDate(domainName):
f = open('domain.csv', 'w')
w = whois.whois(domainName[1])
#print(w)
expirationDate = w.expiration_date
if expirationDate != None:
if type(expirationDate) is list:
try:
delta = expirationDate[0] - now
except:
print sys.exc_info()[0]
else:
try:
delta = expirationDate - now
except:
print sys.exc_info()[0]
data = domainName[0] +','+ domainName[1] + ',' + str(delta.days)
if w.status == None:
message = data + ",No status info found\n"
f.write(message)
else:
print data
f.close()
now = datetime.now()
with open('top-1m.csv', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in reader:
getDomainExpirationDate(row)
The domain list (but i know this doesn't matter):
1,google.com
2,facebook.com
...
Thanks for the answers!
It is probably because the pywhois package is single-threaded and is not suited to handle too many requests at a time.