0

facing error like:

Indentation Error: unintended does not match any outer indentation level,

run_id =id[0]

my code goes like this

else:

                    run_id = id[0]

                    runid_list.append(str(run_id))

                cur.execute("SELECT testcases.slug, WHERE result = 'failed' AND 
                runs.id=" + str(run_id) + "")

                for slug, reason in cur.fetchall():
Servy
  • 202,030
  • 26
  • 332
  • 449
harshitha mg
  • 67
  • 2
  • 6
  • 1
    Read about how python uses indentation for block delimiting here: https://docs.python.org/2.0/ref/indentation.html – Yuvraj Jaiswal Mar 06 '18 at 08:46
  • 2
    Possible duplicate of [I'm getting an IndentationError. How do I fix it?](https://stackoverflow.com/questions/45621722/im-getting-an-indentationerror-how-do-i-fix-it) – jpp Mar 06 '18 at 09:08
  • I cannot see an indentation error in your post, but you post is incomplete. What's coming after the ``fetchall():`` and how is it indented? Are you sure the indention in the else block is in the code the same as you pasted it here? For the rest I think @jpp's link will help you. – allo Mar 06 '18 at 09:51
  • The indentation error was evident before the editing. Check the not edited question – Gsk Mar 06 '18 at 09:56
  • This should not have been edited then. – allo Mar 06 '18 at 10:02
  • I added an edit reverting the changes in the code. Is there some markup to make the whitespace visible? – allo Mar 06 '18 at 10:04

1 Answers1

1

In python code structure indentation is foundamental.

In your code, the problem is that the else statement has 0 indents (0 tabs OR 0 spaces) while the following line (run_id = id[0]) has 2 indents (2 tabs OR 8 spaces).

Dedenting by 1 this line should solve the problem (remove 1 tab or 4 spaces). You will face the same problem with the following line (runid_list.append(str(run_id))).

Anyway, I'd suggest to have a deep look on how indentation works in Python

Gsk
  • 2,929
  • 5
  • 22
  • 29
  • 1
    The number of tabs after the else should not be a problem, as long as they are more than before. You are not limited to 1 tab or 4 spaces. But probably the code has spaces and tabs mixed (I cannot see this from the question). – allo Mar 06 '18 at 09:48
  • you're right. Once you indent, you should mantain the same indentation level. Here the problem is because the first 2 lines have 2 tabs (or 8 spaces) and the next lines have 1 tab (or 4 spaces). The problem may also be solved indenting everything at 2tabs (8spaces) – Gsk Mar 06 '18 at 09:54