Forums

IndentationError: expected an indented block

Hi, I use open and load file as follows, it works fine in local and console. But when I launch to my site, I keep on having error msg : IndentationError: expected an indented block.

            with open(file) as json_file:
                json_file = json.load(json_file)

I dont know what is the problem of this coding in PA. Please help. Thanks.

That would normally mean that your code has inconsistent indentation. Perhaps you could share a screenshot of the file, loaded into the editor?

https://ibb.co/vZKc8Cy

Hmm, that looks OK. Perhaps your indentation is using a mixture of tabs and spaces? That would cause issues like that. If you hit control-comma (command-comma on a Mac) then you'll get a configuration pane at the right of the screen. In there, check the "Show Invisibles" checkbox, and then click on your code again -- that will display whether or not indents are using tabs or spaces, which should help you track down the problem. If you still can't see what the problem is, send us another screenshot showing what it looks like with show invisibles enabled.

Hi, I rewrite all coding again. It seems to work. Thanks for your help!