Search code examples
pythonseleniumtwitterbots

Why this code get error: "Indentation Error: unindent does not match any outer indentation"


My code gating error:

 File "app.py", line 31
    ed = TwitterBot('Someusername', '[email protected]')
                                                        ^
IndentationError: unindent does not match any outer indentation level


i have install 
pip- selenium 
geckodriver

from selenium import webdriver from selenium.webdriver.common.keys import Keys import time

class TwitterBot: def init(self, username, password): self.username = username self.password = password self.bot = webdriver.Firefox()

def login(self):
    bot = self.bot
    bot.get('https://twitter.com/')
    time.sleep(3)
    email = bot.find_element_by_class_name('email-input')
    password = bot.find_element_by_name('sesssion[password]')
    email.clear()
    password.clear()
    email.send_keys(self.username)
    password.send_keys(self.password)
    password.send_keys(Keys.RETURN)
    time.sleep(3)

def like_tweet(self, hashtag):
    bot = self.bot
    bot.get = (
        'https://twitter.com/search?q=' + hashtag + '&src=typd')
    time.sleep(3)

 ed = TwitterBot('Someusername', '[email protected]') #some error
 ed.login()
 ed.like_tweet('webdevelopment')

Solution

  • Python relies heavily on indentation think of an indented block as being like enclosing code between '{' and '}' in java say. so it is important to return to exactly the same indent when you leave the block as you had before the block. In this case you don't do that. It looks as though each of the lines beginning 'ed' starts with a space, remove that space and all will be well.