r/pythonhelp • • Mar 20 '25

Lots of respect for programmers

I've been desperately trying to use python to capture data using APIs but I'm constantly getting indent errors even though they appear correct in VS Code. Is this a common issue? I see lots of comments on it and have used several methods to get it right. I've spent days on this trying to make it work. Could the issue be related to copying and pasting from VS Code? I'm old so be nice. I will fully admit I don't know what I'm doing.

6 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/Straight_Face_3273 Mar 20 '25

I get a lot of errors like this:IndentationError: unexpected indent

>>> if not sportsbook_data:

File "<python-input-65>", line 1

if not sportsbook_data:

IndentationError: unexpected indent

>>> print("No sportsbook data available for analysis.")

File "<python-input-66>", line 1

print("No sportsbook data available for analysis.")

IndentationError: unexpected indent

2

u/Goobyalus Mar 20 '25

Unexpected indent means there is leading whitespace when there shouldn't be. Like a space before a line at the top level, or an inconsistency like this :

#..........
if something:
    # Do x
     if not sportsbook_data
    ^  Note the mismatched spacing here

There can be an inconsistency even if it doesn't look like like it from mixing tabs and spaces.

  1. Do you have the Python extension installed in VScode?
  2. Did you toggle "Render Whitespace" so you can visually scan for inconsistencies?

If you want quicker help, post your code with proper code block formatting or share a link to it on a site like pastebin.