0

This is a common problem it seems on here but in my case I cant find an answer. Why is it saying inconsistent use of tabs and indentation here

def exectute_SQL():    #This function executes SQL to pull counts from a table where it wasnt possible to get an excel 
    con = pypyodbc.connect(conn_str)
    cur = con.cursor()
    sql = "SELECT * FROM Elig_Own.DST_Report_Validation_Test" #WHERE ysn_active = '1'"
    cur.execute(sql)

    rows = cur.fetchall()

    for row in rows:
        strFnd = 0
        strReportName = row[1]
        strSrcName = row[2]
        strDestName = row[3]
        strFileName = row[4]
        try:
            for report in strReportName:
                if report == 'STR_DB Load to SQL':
                    cur.execute("$result = SELECT TOP 1 COUNT(*) FROM Elig_Own.STR_DB GROUP BY LAST_UPDATED ORDER BY LAST_UPDATED DESC;")
                    cur.execute("INSERT INTO Elig_Own.DST_Report_Status_Test(TDate, Report, Records, Status) VALUES(CAST(GetDate() AS Date), 'STR_DB Load to SQL', ?, 'Passed')",(result))
                    con.commit()
        except:
            print("Couldnt execute script")

And This is the error message

C:\Users\cn192406\Documents\Programs>python File_Check_Dart_Functions.py
File "File_Check_Dart_Functions.py", line 73
cur.execute("$result = SELECT TOP 1 COUNT(*) FROM Elig_Own.STR_DB GROUP BY LAST_UPDATED ORDER BY LAST_UPDATED DESC;")

TabError: inconsistent use of tabs and spaces in indentation

Ben Smith
  • 360
  • 4
  • 14

1 Answers1

0

Try this:

def exectute_SQL():  # This function executes SQL to pull counts from a table where it wasnt possible to get an excel
    con = pypyodbc.connect(conn_str)
    cur = con.cursor()
    sql = "SELECT * FROM Elig_Own.DST_Report_Validation_Test"  # WHERE ysn_active = '1'"
    cur.execute(sql)

    rows = cur.fetchall()

    for row in rows:
        strFnd = 0
        strReportName = row[1]
        strSrcName = row[2]
        strDestName = row[3]
        strFileName = row[4]
        try:
            for report in strReportName:
                if report == "STR_DB Load to SQL":
                    cur.execute(
                        "$result = SELECT TOP 1 COUNT(*) FROM Elig_Own.STR_DB GROUP BY LAST_UPDATED ORDER BY LAST_UPDATED DESC;"
                    )
                    cur.execute(
                        "INSERT INTO Elig_Own.DST_Report_Status_Test(TDate, Report, Records, Status) VALUES(CAST(GetDate() AS Date), 'STR_DB Load to SQL', ?, 'Passed')",
                        (result),
                    )
                    con.commit()
        except Exception as e:
            pass

yukashima huksay
  • 5,834
  • 7
  • 45
  • 78
  • still same error. I had an exception in there just forgot to include it in the snippit – Ben Smith Sep 23 '19 at 16:49
  • @BenSmith try to copy paste my code exactly from here. you probably have tabs and spaces mixed up in your code. you should either always use tabs for indention or always use spaces. You should configure your editor to always replace tabs with spaces or vice versa. – yukashima huksay Sep 23 '19 at 16:53