G
G
glebandopalas2021-06-20 18:08:23
Python
glebandopalas, 2021-06-20 18:08:23

What's wrong with my Python OOP?

I've been writing an Instagram bot for some time now using the Selenium framework. Recently, I decided to move most of the code into a class so that everything is correct and orthodox, and it was already neatly sorted into functions, and the functions themselves were stuffed into the class. I felt a sharp pain somewhere in my chest.
Here is a small snippet from the main code that will clearly demonstrate the essence of the problem:

from data import login, password #данные аккаунта, которые программа вводит при авторизации
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

class Newbie():

    def __init__(self, login, password):
        self.login = login
        self.password = password
        self.driver = webdriver.Firefox()

    def logging(self, login, password):
        driver = self.driver
        try:
            driver.get("https://www.instagram.com")
            time.sleep(5)

            login_input = driver.find_element_by_name("username")
            login_input.clear()
            login_input.send_keys(login)

            time.sleep(5)

            password_input = driver.find_element_by_name("password")
            password_input.clear()
            password_input.send_keys(password)
            password_input.send_keys(Keys.ENTER)
            time.sleep(5)
        except Exception as ex:
            print(ex)
            self.killdriver() #функция которая закрывает браузер

Newbie.logging(login, password)

TypeError: logging() missing 1 required positional argument: 'password'


The program clearly tells me that the function is missing one argument when called, although I specified everything as planned, and before that everything worked fine. Please explain what is wrong here, because active googling over the past two days has not yielded any result, except for headaches and suicidal thoughts.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-06-20
@glebandopalas

user = Newbie(login, password)
Some kind of wrong OOP.
The logging method probably needs to be renamed, for example, to auth_user
AND use class instance variables in it, i.e. self.passwordandself.login

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question