AttributeError: 模块“whois”没有属性“whois”

如何解决AttributeError: 模块“whois”没有属性“whois”

我正在运行我的机器学习代码并收到此错误-

    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,')
    file_obj.close()

我已经尝试过卸载 whois,然后使用命令 pip install python-whois 重新安装 python-whois。但这对错误没有帮助。

我如何才能了解哪里出了问题,以及如何纠正?

解决方法

错误原因:
您尚未在系统上安装 whois 命令。
Ubuntu:使用 sudo apt install whois
Windows:从 here

下载并安装

首先使用 whoispip uninstall whois 卸载任何 pip uninstall python-whois 模块

解决方案 1:使用 python-whois

安装 python-whoispip install python-whois
然后确保您已经在您的机器上安装了 whois 命令。
那么你的代码应该可以工作了。

解决方案 2:使用 whois

在您的机器上安装 whois 命令。如果您使用的是 ubuntu sudo apt install whois 就可以了。
使用 pip install whois 安装 whois 模块,
然后在代码中使用 whois.query() 而不是 whois.whois()

Source

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?