rudehlabya
rudehlabya

Reputation: 119

Receiving tab error "inconsistent use of tabs and spaces in indentation" even after converting from spaces to tabs in visual studio code

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.

Upvotes: 0

Views: 1610

Answers (1)

Molly Wang-MSFT
Molly Wang-MSFT

Reputation: 9511

  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.

Upvotes: 1

Related Questions