I am running my ML code and getting this error-
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'
My code is:
# -*- 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')
The code of file p2.py is:
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()
I have already tried uninstalling whois and then reinstalling python-whois using the command pip install python-whois. But that hasn't helped with the error.
How can I understand what is going wrong, and how I can correct it?
Reason for your error:
You have not installed the whois command on your system.
Ubuntu: Use sudo apt install whois
Windows: Download and install from here
First uninstall any whois module with pip uninstall whois and pip uninstall python-whois
Solution 1: Use python-whois
Install python-whois with pip install python-whois
Then make sure you already installed the whois command on your machine.
Then your code should work.
Solution 2: Use whois
Install whois command on your machine. If you are on ubuntu sudo apt install whois will do.
Install whois module with pip install whois,
Then use whois.query() instead of whois.whois() in your code.
Source
Related
here i tryied to run script with pypy3 c.py but above error occured ,
i installed pypy3 -m pip install pyshark but ...
pypy3 c.py
ModuleNotFoundError: No module named 'lxml.objectify'
import pyshark
import pandas as pd
import numpy as np
from multiprocessing import Pool
import re
import sys
temp_array = []
cap = pyshark.FileCapture("ddos_attack.pcap")
#print(cap._extract_packet_json_from_data(cap[0]))
def parse(capture):
print(capture)
packet_raw = [i.strip('\r').strip('\t').split(':') for i in str(capture).split('\n')]
packet_raw = map(lambda num:[num[0].replace('(',''),num[1].strip(')').replace('(','')] if len(num)== 2 else [num[0],':'.join(num[1:])] ,[i for i in packet_raw])
raw = list(packet_raw)[:-1]
cols = [i[0] for i in raw]
vals = [i[1] for i in raw]
temp_array.append(dict(zip(cols,vals)))
return dict(zip(cols,vals))
def preprocess_dataset(x):
count = 0
temp = []
#print(list(cap))
#p = Pool(5)
#r = p.map(parse,cap)
#p.close()
#p.join()
#print(r)
try:
for i in list(cap):
temp.append(parse(i))
count += 1
except Exception:
print("somethin")
data = pd.DataFrame(temp)
print(data)
data = data[['Packet Length','.... 0101 = Header Length','Protocol','Time to Live','Source Port','Length','Time since previous frame in this TCP stream','Window']]
data.rename(columns={".... 0101 = Header Length": 'Header Length'})
filtr = ["".join(re.findall(r'\d.',str(i))) for i in data['Time since previous frame in this TCP stream']]
data['Time since previous frame in this TCP stream'] = filtr
print(data.to_csv('data.csv'))
here i tryied to run script with pypy3 c.py
but above error occured ,
i installed pypy3 -m pip install pyshark but ...
Check your terminal settings.
Try to use another compiler like PyCharm.
It seems lxml is not installed correctly. It is hard to figure out what is going on since you only show the last line of the traceback, and do not state what platform you are on nor what version of PyPy you are using. The lxml package is listed as a requirement for pyshark, so it should have been installed. What happens when you try import lxml ?
I'm trying to run the deit colab notebook found here:
https://colab.research.google.com/github/facebookresearch/deit/blob/colab/notebooks/deit_inference.ipynb
but I'm running into an issue in the second cell, specifically the import timm line, which returns this:
ImportError: cannot import name 'container_abcs' from 'torch._six'
Issue related to this error here:
Try a specific version of timm library:
!pip install timm==0.3.2
when I install torch==1.9.0 and torch-geometric,
the old code has the errors.
here is my solution:
TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])
if TORCH_MAJOR == 0:
import collections.abc as container_abcs
else:
from torch._six import container_abcs
change to:
TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])
if TORCH_MAJOR == 1 and TORCH_MINOR < 8:
from torch._six import container_abcs,int_classes
else:
import collections.abc as container_abcs
int_classes = int
In my case it worked with
pip install timm==0.4.12
I am trying to run a python code that will help me in connecting & extracting data from YouTube Data API v3. However, the moment i try to run the code, it give me the following error right at the first line:
File "C:/Users/asaxena/Desktop/py4e/Social Media Data Analytics/youtube_search.py", line 3, in <module>
from apiclient.discovery import build
ModuleNotFoundError: No module named 'apiclient'
I have already installed google-api-python-client in my working directory through the command: pip install --upgrade google-api-python-client
But its not helping me in running the code.
from apiclient.discovery import build
import argparse
import csv
import unidecode
def youtube_search(options):
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY)
search_response = youtube.search().list(q=options.q, part="id,snippet", maxResults=options.max_results).execute()
videos = []
channels = []
playlists = []
csvFile = open('video_result.csv','w')
csvWriter = csv.writer(csvFile)
csvWriter.writerow(["title","videoId","viewCount","likeCount","dislikeCount","commentCount","favoriteCount"])
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
title = search_result["snippet"]["title"]
title = unidecode.unidecode(title) # Dongho 08/10/16
videoId = search_result["id"]["videoId"]
video_response = youtube.videos().list(id=videoId,part="statistics").execute()
for video_result in video_response.get("items",[]):
viewCount = video_result["statistics"]["viewCount"]
if 'likeCount' not in video_result["statistics"]:
likeCount = 0
else:
likeCount = video_result["statistics"]["likeCount"]
if 'dislikeCount' not in video_result["statistics"]:
dislikeCount = 0
else:
dislikeCount = video_result["statistics"]["dislikeCount"]
if 'commentCount' not in video_result["statistics"]:
commentCount = 0
else:
commentCount = video_result["statistics"]["commentCount"]
if 'favoriteCount' not in video_result["statistics"]:
favoriteCount = 0
else:
favoriteCount = video_result["statistics"]["favoriteCount"]
csvWriter.writerow([title,videoId,viewCount,likeCount,dislikeCount,commentCount,favoriteCount])
csvFile.close()
At the end, I should be able to establish a successful connection with YouTube Data API v3, and extract data in a csv file.
You're importing a non-existing module. According to the documentation here you should be using:
from googleapiclient.discovery import ...
instead of:
from apiclient.discovery import ...
I solved it:
I manually installed the "google-api-python-client-master" separately in my working directory and then ran: "setup.py install" from the command line.
I then manually installed "Unidecode-master" separately within the unzipped "google-api-python-client-master" folder and then ran: "setup.py install" from the command line.
I then ran the above code, and it worked.
I believe you would have to install the API folders separately, or it won't work. Hope this is useful.
I can't import pytagcloud in jupyter notebook. How do I solve this problem? I searched some tutorials and also installed other packages required but still doesn't work?
Do you have any suggestion?
Here is my code. Thanks.
import pytagcloud as pytagcloud
import codecs
from bs4 import BeautifulSoup
from konlpy.tag import Twitter
# utf-16 인코딩으로 파일을 열고 글자를 출력하기 --- (※1)
samsung = codecs.open("samsung.txt", encoding="utf-8")
line = samsung.readlines()
twitter = Twitter()
word_dic = {}
for line in line:
malist = twitter.pos(line)
for word in malist:
if word[1] == "Noun": # 명사 확인하기 --- (※3)
if not (word[0] in word_dic):
word_dic[word[0]] = 0
word_dic[word[0]] += 1 # 카운트하기
# 많이 사용된 명사 출력하기 --- (※4)
keys = sorted(word_dic.items(), key=lambda x:x[1], reverse=True)
for word, count in keys[:40]:
print("{0}({1}) ".format(word, count), end="")
print()
keys
import pytagcloud
taglist = pytagcloud.make_tags(keys, maxsize = 80)
taglist
pytagcloud.create_tag_image(taglist, 'wordcolud.jpg', size = (900,600), fontname = 'Nobile', rectangular = False)
%matplotlib inline
import matplotlib.pyplot as plt
from wordcloud import WordCloud as wordcloud
wordcloud = WordCloud(stopwords = stopwords)
wordcloud = wordcloud.generate_from_keys(keys)
wordcloud = WordCloud().generate(keys)
draw_wordcloud_from_rss(keys)
cmd:pytagcloud
cmd:pygame
cmd:simplejson
jupyter notebook: pytagcloud
I asked one of my colleagues and she gave the answer!
So the problem was simple. I installed all those libraries in 'cmd'
but I had to install them in "Anaconda prompt".
So, if you have same problem as mine, try this.
# Anaconda prompt
pip install pygame
pip install -U pytagcloud
pip install simplejson
jupyter notebook.
# Import.
I succeeded to import pygame, pytagcloud and simplejson libraries.
Yet, I have still errors in my code of the post above and there is more libraries to install(konply..etc). error is everywhere!
Anyway, I hope this helps someone.
I have a problem with my pandas. First I tried easy-install on cd C:\Python27\Scrips...doing. easy_install.exe numpy, and easy_install.exe pandasbut only the numpy worked, the pandas didnt, so I used pip to install. and it worked on both. But going back to my code, when I tested it,
heres my code:
import fileinput
import csv
import numpy
import pandas
#records = pe.iget_records(file_name="test.xlxs")
records = pd.read_csv('test.csv', header=None, nrows=5)
#To Write ni
cho = raw_input("\nStart Forecaster on file?:<1/0>")
if cho == 1:
for record in records:
rem = df.iloc([i], [0])
print(rem)
sold1 = df.iloc([i], [1])
print(sold1)
sold2 = df.iloc([i], [2])
print(sold2)
rem = int(rem)
sold1 = int(sold1)
sold2 = int(sold2)
result = forecast(rem,sold1,sold2)
print(result)
df.set_value([i], [4], result)
pd.to_csv('test.csv')
print "Forecast Complete! Please check the file!"
else:
quit()
But i get this error:
Traceback (most recent call last):
File "tester.py", line 4, in <module>
import pandas
File "C:\Python27\lib\site-packages\pandas\__init__.py", line 25, in <module>
from pandas import hashtable, tslib, lib
File "pandas\src\numpy.pxd", line 157, in init pandas.hashtable (pandas\hashtable.c:40866)
ValueError: numpy.dtype has the wrong size, try recompiling. Expected 52, got 56
You will need to remove all previous installations of pandas and numpy because you installed them successively too many times making the libraries confused. After deleting them, reinstall pandas and numpy by using pip, like so:
pip install numpy
pip install pandas