Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46300

Re: IndentationError: expected an indented block but it's there

Date 2013-05-28 09:55 -0600
From Michael Torrie <torriem@gmail.com>
Subject Re: IndentationError: expected an indented block but it's there
References <V54pt.161708$Zp1.55817@en-nntp-15.dc1.easynews.com>
Newsgroups comp.lang.python
Message-ID <mailman.2301.1369756559.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 05/28/2013 09:32 AM, JackM wrote:
> Having a problem getting a py script to execute. Got this error:
> 
> File "/scripts/blockIPv4.py", line 19
>      ip = line.split(';')[0]
>       ^
> IndentationError: expected an indented block
> I'm perplexed because the code that the error refers to *is* indented:
> with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile:
>      for line in inFile.readlines():
>          ip = line.split(';')[0]
>          output = os.popen( '/etc/sysconfig/iptables -A INPUT -s ' + ip 
> + ' -j REJECT' )
>          logFile.write(ip+' - Has been blocked\n')
> 
> 
> What am I missing here?

Indentation has to be consistent.  likely the for line is indented with
spaces and the next line with a tab.  You can use tabs and spaces, but
you have to be consistent with how you use them.  IE if level 1 is
indented with spaces, then level 2 has to be indented with spaces up to
level 1 as well.  Hope that makes sense.


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

IndentationError: expected an indented block but it's there JackM <notreal@earthlink.net> - 2013-05-28 11:32 -0400
  Re: IndentationError: expected an indented block but it's there Michael Torrie <torriem@gmail.com> - 2013-05-28 09:55 -0600
  Re: IndentationError: expected an indented block but it's there Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-28 16:01 +0000
  Re: IndentationError: expected an indented block but it's there Peter Otten <__peter__@web.de> - 2013-05-28 18:19 +0200
  Re: IndentationError: expected an indented block but it's there Chris Angelico <rosuav@gmail.com> - 2013-05-29 02:31 +1000
  Re: IndentationError: expected an indented block but it's there Peter Otten <__peter__@web.de> - 2013-05-28 18:53 +0200
  Re: IndentationError: expected an indented block but it's there Chris Angelico <rosuav@gmail.com> - 2013-05-29 17:59 +1000

csiph-web