0

So I am getting an error in my flask app which says:

File app.py, line 13
first = request.form.get('first')

IndentationError: expected an indented block

Here is my app.py code

import time
import requests
import requests_cache

from flask import Flask, render_template, request, jsonify

app = Flask(__name__)



@app.route('/', methods=['GET', 'POST'])
def home():
    if request.method == 'POST':
        first = request.form.get('first')
        url = "http://myAPIURL.com/ws/spm/search/perfid/{0}".format(first)
        response = requests.get(url)
        return jsonify(response.json())
    return render_template('index.html')


if __name__ == '__main__':
    app.run(debug=True)

I have checked the indentations and they seem to be fine to me,

Can someone please point out what I am doing wrong?

eLRuLL
  • 18,488
  • 9
  • 73
  • 99
Akki
  • 2,179
  • 8
  • 21
  • 37
  • 6
    Are you sure that you're not mixing tabs and spaces? – Celeo Dec 14 '15 at 18:15
  • @Celeo: Ok I will check this again now. – Akki Dec 14 '15 at 18:18
  • Yes , I had used space in one indentation :) It seems I need some sleep inbetween too :P – Akki Dec 14 '15 at 18:22
  • 3
    You should use space for all your python indentation! See http://stackoverflow.com/questions/120926/why-does-python-pep-8-strongly-recommend-spaces-over-tabs-for-indentation for the reasoning (and arguments!) – Tom Dalton Dec 14 '15 at 18:22

1 Answers1

0

The problem certainly lies on mixing tabs and spaces. You should always indent using spaces and change the settings on your editor to use spaces instead of a tab character, that way your indentation will be consistent between different systems/editors.

But if you prefer to really indent your code using tabs characters, at least stick to the golden rule of 'Never mix tabs and spaces'. Don't use both on your code as it will lead to errors and maybe unwanted behaviours (a line ends up being indented under a different block, for example)

It is also highly recommended by PEP8 to use spaces. And this question is a discussion about why it is recommended.

Community
  • 1
  • 1
0rkan
  • 845
  • 2
  • 18
  • 34