Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'configure': 0.05; 'output': 0.05; 'error:': 0.07; 'see:': 0.07; '"if': 0.09; '*is*': 0.09; 'exec': 0.09; 'here?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:o 50': 0.09; 'spaces': 0.09; 'width': 0.09; 'python': 0.11; 'contents:': 0.16; 'indent': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'tab': 0.16; 'tabs': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'input': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'refers': 0.24; 'script': 0.25; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'correct': 0.29; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; '"",': 0.31; 'file': 0.32; '(most': 0.33; 'actual': 0.34; 'problem': 0.35; 'editor': 0.35; 'expected': 0.38; 'configured': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'subject:there': 0.68; 'eight': 0.74; 'simulation': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: IndentationError: expected an indented block but it's there Date: Tue, 28 May 2013 18:19:47 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084866c.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369757998 news.xs4all.nl 15980 [2001:888:2000:d::a6]:50701 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46306 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? If you are mixing tabs and spaces to indent your code and have your editor configured with a tab width other than eight your code may look correct when it isn't. A simulation in the interactive interpreter: The actual file contents: >>> s = "if 1:\n\tif 2:\n \tprint 'hi'" What you see: >>> print s.expandtabs(4) if 1: if 2: print 'hi' >>> exec s.expandtabs(4) hi What Python "sees": >>> print s.expandtabs(8) if 1: if 2: print 'hi' >>> exec s Traceback (most recent call last): File "", line 1, in File "", line 3 print 'hi' ^ IndentationError: expected an indented block Solution: configure your editor to use four spaces for indentation.