-3

IndentationError: unexpected unindent WHY? Here's my code:

from praw.models import MoreComments
import praw
import giris
import time
import os

def bot_login():
    print("Loggin in...")
    r = praw.Reddit(username = giris.username,
            password = giris.password,
            client_id = giris.client_id,
            client_secret = giris.client_secret,
            user_agent = "karton_bardak_bot")
    print("Logged in!")
    return r

info="""
\n
\n
\n
^(ben bot) \n
\n
^(bruh)
"""

subreddit=r.subreddit("shithikayeler")

def run_bot(r, comments_replied_to):
    print("Obtaining 25 comments...")
    for submission in subreddit.new():
        toReply=True
        for top_level_comment in submission.comments:
            if isinstance(top_level_comment, MoreComments):
                continue
            if not submission.is_self:
                toReply=False
            if top_level_comment.author=="karton_bardak_bot" or submission.selftext=='':
                toReply=False
                print("PASSED "+ submission.url)
                log.write("PASSED "+ submission.url+"\n")
        if toReply:
            try:
                new=reply(submission.selftext, info)
                submission.reply(new)

            except Exception as e:
                log.write("ERROR: " + str(e) + "   on submission " + submission.url)
            print("REPLIED "+ submission.url)
            log.write("REPLIED "+submission.url+"\n")
            try:
                time.sleep(60)   

r = bot_login

while True:
    run_bot(r)

It says:

 File "bot.py", line 57
    r = bot_login
    ^
IndentationError: unexpected unindent

Why? I have checked a thousands times and I can't find the problem. Pls help.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • 1
    Such errors are often caused by something above the place mentioned by compiler/interpreter. This is also the case here: `try` needs `except` and/or `finally` – Michael Butscher May 21 '20 at 08:28

1 Answers1

0

Because you start a

try:

block with out giving it the needed

except:

part... exactly here:

            try:
                time.sleep(60)   

r = bot_login

so it complains about r = bot_login being maliciously wrong indented.

The code either expects you to stay inside the try: indentation to add more code or ex-dent once and add the except ... : part of the statement followed by another indent for it`s code.

See python.org tutorial about handling exceptions

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69