使用pywhois包获取错误

时间:2015-10-13 15:34:09

标签: python pywhois

我正在创建一个python脚本,它遍历包含域名的列表,在大多数情况下它运行良好(从https://bitbucket.org/richardpenman/pywhois下载包),但有时我得到错误说: {{1我可以忽略此错误吗?

我的python代码是:

Socket Error: [Errno 10054] An existing connection was forcibly closed by the remote host

域名列表(但我知道这无所谓):

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)

感谢您的回答!

0 个答案:

没有答案