Getting error with pywhois package

Question:

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 foundn"
            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!

Asked By: C1sc0

||

Answers:

It is probably because the pywhois package is single-threaded and is not suited to handle too many requests at a time.

Answered By: C1sc0
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.