属性错误:模块“whois”没有“whois”属性。

3
我正在运行我的机器学习代码,但出现了以下错误-
    Enter website name=> www.google.com
Traceback (most recent call last):
  File "Dphishing.py", line 12, in <module>
    p2.category2(website)
  File "C:\xampp\htdocs\Detect_Phishing_Website\p2.py", line 8, in category2
    page = whois.whois(website)
AttributeError: module 'whois' has no attribute 'whois'

我的代码如下:

# -*- coding: utf-8 -*-

import p1
import p2
import p3
import p4
import pandas as pd
#import numpy as np

website = str(input("Enter website name=> "))
p1.category1(website)
p2.category2(website)
p3.category3(website)
p4.category4(website)


read = pd.read_csv(r'C:\Users\Anushree\Desktop\college\4th year project\Detect_Phishing_Website\phishing5.txt',header = None,sep = ',')
read = read.iloc[:,:-1].values
dataset = pd.read_csv(r'C:\Users\Anushree\Desktop\college\4th year project\Detect_Phishing_Website\Training Dataset1.csv')
X = dataset.iloc[:,:-1].values  
y = dataset.iloc[:,-1].values

from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.2,random_state = 1001)

from sklearn.ensemble import RandomForestRegressor
regressor = RandomForestRegressor(n_estimators = 10,criterion = "mse",random_state = 2)
regressor.fit(X_train,y_train)                             

y_pred = regressor.predict(X_test)


from sklearn.model_selection import cross_val_score
accuracy = cross_val_score(estimator = regressor,X=X_train,y=y_train,cv = 5)
accuracy.mean()
accuracy.std()


Detect_phishing_website = regressor.predict(read)

if Detect_phishing_website == 1:
    print("legitimate website")
elif Detect_phishing_website == 0:
    print ('suspicious website')
else:
    print('phishing website')

文件p2.py的代码如下:

import re
import whois

def category2(website):
        
    file_obj = open(r'C:\Users\Anushree\Desktop\college\4th year project\Detect_Phishing_Website\phishing5.txt','a')
    #8 Domain Registration Length
    page = whois.whois(website)
    if type(page.expiration_date) == list:
        domain_reg_len = (page.expiration_date[0] - page.creation_date[0]).days
    else:
        domain_reg_len = (page.expiration_date - page.creation_date).days
    #print domain_reg_len
    if domain_reg_len <= 365:
        file_obj.write('-1,')
    else:
        file_obj.write('1,')
    #9 Using Non-Standard Port 
    match_port = re.search(':[//]+[a-z]+.[a-z0-9A-Z]+.[a-zA-Z]+:([0-9#]*)',website)
    if match_port:
        print (match_port.group())
        if match_port.group(1) == '#':#represent multiple ports are active on url
            file_obj.write('-1,')
        else:
            file_obj.write('1,')
    else:
        file_obj.write('1,')
    file_obj.close()

我已经尝试卸载 whois,然后使用命令 pip install python-whois 重新安装 python-whois,但这并没有解决错误。
我该如何理解出现了什么问题,并如何纠正它?

请检查whoispythonwhois的正确用法 - https://dev59.com/JV0a5IYBdhLWcg3w88o0#29773604 - marmeladze
这个能帮到你吗?(https://pypi.org/project/whois/) - Aven Desta
这个回答解决了你的问题吗?检查域名是否已注册 - Prayson W. Daniel
这似乎是一个已知的包混淆问题。我已经删除了我的答案并标记为可能重复。 - Prayson W. Daniel
1个回答

2

错误原因:
您的系统上未安装whois命令。
Ubuntu:使用sudo apt install whois命令安装
Windows:从此处下载并安装

首先,通过pip uninstall whoispip uninstall python-whois命令卸载任何whois模块

解决方案1:使用python-whois

使用pip install python-whois命令安装python-whois模块
然后确保您的机器上已经安装了whois命令。
然后您的代码应该可以工作。

解决方案2:使用whois

在您的计算机上安装whois命令。如果您使用的是ubuntu,则可以使用sudo apt install whois命令进行安装。
使用pip install whois命令安装whois模块,
然后在您的代码中使用whois.query()代替whois.whois()

来源


我应该先卸载Python-whois才能让whois正常工作吗? - weirdo 2045
@Anu2045 是的,只需执行 pip uninstall python-whois 即可。 - Aven Desta
命令pip install whois安装了whois-0.9.7。但是在运行文件Dphishing.py时,错误仍然存在。 请帮忙。 - weirdo 2045
是的。我已经按照您的指示卸载了python-whois并安装了whois。但是仍然出现相同的错误-输入网站名称=> www.google.com Traceback (most recent call last): File "Dphishing.py", line 12, in <module> p2.category2(website) File "C:\xampp\htdocs\Detect_Phishing_Website\p2.py", line 9, in category2 page = whois.whois(website) AttributeError: 模块'whois'没有'whois'属性 - weirdo 2045
问题还在,我正在使用Windows 10。 - weirdo 2045
@Anu2045,你在Windows上安装了whois命令吗?如果没有,请前往此处下载并安装whois命令以供使用。 - Aven Desta

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接