0
votes

I keep receiving this error from my application:

File "", line 67

for o in obj["physical_address"]:
                                ^

TabError: inconsistent use of tabs and spaces in indentation

Here is my code:

@app.route('/location')
def get_testing_location():
    """Return selected state from drop down menu"""

    state = request.args['testing-state']
    url = f'https://covid-19-testing.github.io/locations/{state.lower()}/complete.json'
    res = requests.get(url)
    data = res.json()
    for obj in data:
        if obj["physical_address"]:
            for o in obj["physical_address"]:
                add=o["address_1"] 
                state=o["city"]
                print(f'{add} {state}')

    import pdb
    pdb.set_trace()

I have converted my visual studio code editor to use tabs instead of spaces and yet I still receive the same error.

1
does the editor convert spaces to tabs or just from now on it will be tabs not spaces? even if it converts, perhaps it doesn't convert e.g. 2 spaces into one tab (if it's 4 spaces). In which case you could try to convert all tabs to spaces in the document and see if you still get the error - Matthias
I see spaces on the if obj["physical_address"]: line. - user2357112 supports Monica
@Carcigenicate: You need to use the "Edit" view. The rendered output converts tabs to spaces. - user2357112 supports Monica

1 Answers

1
votes
  1. Add "editor.renderWhitespace": "all" in Settings.json. There may be spaces and tabs mixed in your code. It's recommended to indent all by spaces.

  2. Convert indentation to 4 spaces:

enter image description here

Save the file to see if the error goes away.