Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Attribute Error
#1
I am doing an online course and when i run the program, i get an error message of:

Output:
Traceback (most recent call last): File "vulnerability_scanner.py", line 9, in <module> vuln_scanner.session.post("http://10.0.2.4/dvwa/login", data=data_dic) AttributeError: Scanner instance has no attribute 'session' root@kali:~/PycharmProjects/vulnerability_scanner#
Here is a copy of my code..now, im using pycharm so I have two different programs that i have separately coded that work in tandem, if you will so the scanner is here:
#!/usr/bin/env python

import requests
import re
import urlparse


class Scanner:
    def __init__(self, url):
        self.target_url = url
        self.target_links = []
        self.session = requests.Session()

    def extract_links_from(self, url):
        response = self.session.get(url)
        return re.findall('(?:href=")(.*?)"', response.content.decode('utf-8', 'ignore'))

    def crawl(self, url=None):
        if url is None:
            url = self.target_url
        href_links = self.extract_links_from(url)
        for link in href_links:
            link = urlparse.urljoin(url, link)

            if "#" in link:
                link = link.split("#")[0]

            if self.target_url in link and link not in self.target_links:
                self.target_links.append(link)
                print(link)
                self.crawl(link)
And the other program, named vulnerability_scanner is here:
#!/usr/bin/env python

import scanner

target_url = "http://10.0.2.4/dvwa/"
data_dic = {"username": "admin", "password": "password", "Login": "submit"}

vuln_scanner = scanner.Scanner(target_url)
vuln_scanner.session.post("http://10.0.2.4/dvwa/login", data=data_dic)

vuln_scanner.crawl()
(The url is apart of metaslpoitable, a vulnerable operating system by design)

Running the program is the conventional vulnerability_scanner.py and sure enough, I get the error message.


Any and all help, along with formatting my code to whatever you guys ask would be great.
Reply
#2
One thing that comes to my mind - you changed scanner.py to include Scanner.session and didn't save the file yet. I don't remember if PyCharm had autosave function. The other - you have more than one scanner.py in different locations and it import a different one than the one you edit and expect to be imported.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling an class attribute via a separate attribute in input wiggles 7 2,890 Apr-04-2020, 10:54 PM
Last Post: wiggles
  Attribute error in code 3DEN 1 2,410 Dec-09-2019, 10:43 AM
Last Post: buran
  ERROR NoneType object has no attribute content denizkb 1 2,634 Nov-21-2019, 01:18 PM
Last Post: denizkb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020