top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

IndentationError: expected an indented block but it's there

0 votes
463 views

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 blockedn')

What am I missing here?

posted May 28, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Whenever you get perplexing indentation errors, suspect an inconsistency due to mixed tabs and spaces.

Tabs good. Spaces good. Tabs and spaces together, bad. You can run the tabnanny module over your source code:

python -m tabnanny 

to convert indentation to all spaces.

answer May 28, 2013 by anonymous
0 votes

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.

answer May 28, 2013 by anonymous
Similar Questions
+2 votes

Let's say I have two identical branches: master and topic. In master I remove some code, i.e. function bar(). In topic I do the same (commit) and after some time I realize I need bar() and revert previous commit
with removal.

So I end with master with no bar() and topic with bar() in its original state. When I merge I get code without bar() and no merge conflict (recursive or resolve strategies). Is it possible to detect such situations as conflicts? When bar() is C++ virtual there is no possibility to catch this with compiler.

+4 votes

I'm using Bulk Export/ Import Extension in OpenCart .export is working well but,when import file Error:Uploaded file is not a valid spreadsheet file or its values are not in the expected formats!

+4 votes

I am getting the following error -

UserProfile.picture: (fields.E210) Cannot use ImageField because Pillow is not installed.

HINT: Get Pillow at https://pypi.python.org/pypi/Pillow or run command "pip install pillow".
System check identified 1 issue (0 silenced).

This is installation Summary of pillow

PIL SETUP SUMMARY
version Pillow 2.6.1
platform linux 3.4.2 (default, Oct 8 2014, 13:08:17) [GCC 4.9.1]

--- TKINTER support available
--- JPEG support available
--- OPENJPEG (JPEG2000) support not available
--- ZLIB (PNG/ZIP) support available
--- LIBTIFF support available
--- FREETYPE2 support available
--- LITTLECMS2 support available
--- WEBP support available
--- WEBPMUX support available
0 votes

I have the following script which does not return anything, no apparent mistake but my output file is empty.I am just trying to extract some decimal number from a file according to their names which are in another file. from collections import defaultdict import numpy as np

ercc_contigs= {}
for line in open ('Faq_ERCC_contigs_name.txt'):
 gene = line.strip().split()

ercc_rpkm = defaultdict(lambda: np.zeros(1, dtype=float))
output_file = open('out.txt','w')

rpkm_file = open('RSEM_Faq_Q1.genes.results.txt')
rpkm_file.readline()
for line in rpkm_file:
 line = line.strip()
 columns = line.strip().split()
 gene = columns[0].strip()
 rpkm_value = float(columns[6].strip())
 if gene in ercc_contigs:
 ercc_rpkm[gene] += rpkm_value

ercc_fh = open ('out.txt','w')
for gene, rpkm_value in ercc_rpkm.iteritems():
 ercc = '{0}t{1}n'.format(gene, rpkm_value)
 ercc_fh.write (ercc)

If someone could help me spot what's wrong it would be much appreciate cheers

0 votes

In my Django application, I can handle my data in the admin page. Now, I like to export the admin page data into some formats like Excel, CSV or alteast JSON dump.

Is it possible? Anyone can clarify, please?

...