AnsweredAssumed Answered

Unsupported operand type(s) for +: 'NoneType' and 'NoneType'

Question asked by jzumbadoCFG on Oct 24, 2019
Latest reply on Nov 19, 2019 by jzumbadoCFG

Most distinguish colleagues,

 

I'm not very good a coding. In fact...I'm a beginner. Yet, I inherited this python script that does compression and analysis and I can't figure out why when we switch from 10.3.1 to 10.6.1 the script won't run anymore. It gives me the following error message:

 

ERROR: Step1_CompressAnalyze.py: Line 35
ERROR: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

 

Line 35 

dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()  # type:

Here is the whole script. 

import arcpy

def main(parentSDE):
    import os
    import sys
    import datetime

    if parentSDE == '':
        parentSDE = arcpy.GetParameterAsText(0)

    TOOLROOT = os.path.abspath(os.path.dirname(sys.argv[0])).rpartition("\\")[0]
    tool_folder = os.path.join(TOOLROOT,"ToolData")
    reportFolder = os.path.join(TOOLROOT,"Reports","Daily")
    stepName = "Step1_"

    try:
        #Delete older logs.
        map(os.unlink, (os.path.join(reportFolder,f) for f in os.listdir(reportFolder) if stepName in f))
        reportFile = os.path.join(reportFolder,"Step1_CompressandAnalyze.txt")
        logFile = open(reportFile,'a')

        arcpy.env.workspace = parentSDE

        print "I've done it!"

        #1. Find all feature datasets, feature classes, tables
        fcList = []
        unversionedList = []
        tableList = []
        unversionedTable = []

        userName = 'OWNER'
        print ("Nailed it!")
        dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()  # type:
       

        print arcpy.GetMessages()

        for dataset in arcpy.ListDatasets("", "Feature"):
            dataList += arcpy.ListFeatureClasses(feature_dataset=dataset)
        arcpy.RebuildIndexes_management(parentSDE, "SYSTEM", dataList, "ALL")
        arcpy.AnalyzeDatasets_management(parentSDE, "SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")

        print ("Analyze Complete")
      

        #2. Compress database
        logFile.write("\nCompressed:\n")
        compressTable = os.path.join(parentSDE,[f for f in arcpy.ListTables() if "compress_log" in f.lower()][0])
        fieldList = [f.name for f in arcpy.ListFields(compressTable)]

        arcpy.Compress_management(parentSDE)

        with arcpy.da.SearchCursor(compressTable,fieldList) as cur:
            for row in cur:
                lastRow = ",".join(str(x) for x in row[:])


        logFile.write(",".join(fieldList))
        logFile.write("\n")
        logFile.write(lastRow)
        logFile.write("\n")

        print ("I've done it the right way!")
            
     
        #3. Analyze last time
        arcpy.RebuildIndexes_management(parentSDE, "NO_SYSTEM", dataList, "ALL")
        arcpy.AnalyzeDatasets_management(parentSDE, "NO_SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")

        ## Review report for errors
        errorLogs = []
        allLogs = []
        for (dirPath,dirName,fileNames) in os.walk(reportFolder):
            for fileName in fileNames:
                if stepName in fileName:
                    reportFile = os.path.join(reportFolder,fileName)
                    with open(reportFile) as f:
                        content = [x.upper() for x in f]
                        if "FAILURE" in content or "IN PROGRESS" in content or "UNSUCCESSFUL" in content:
                            errorLogs.append(reportFile)
                            arcpy.AddWarning("Warning or Error found: %s"%reportFile)
                        else:
                            allLogs.append(reportFile)

        arcpy.SetParameterAsText(1,errorLogs)
        return (allLogs,errorLogs)

    except Exception, e:
        import traceback, sys, os
        tb = sys.exc_info()[2]       
        arcpy.AddError("%s: Line %i"%(str(os.path.basename(__file__)),tb.tb_lineno))
        arcpy.AddError(e)
        logFile.write("%s: Line %i\n"%(str(os.path.basename(__file__)),tb.tb_lineno))
        logFile.write(str(e))
        logFile.close()
        arcpy.SetParameterAsText(1,reportFile)
        return([],[reportFile])
    finally:
        logFile.close()
        arcpy.AddMessage("--%s Complete"%(str(os.path.basename(__file__)).replace(".pyc",'')))
if __name__ ==  "__main__":
    parentSDE = ''
    main(parentSDE)

print "I'm done compressing!"

After I run it I see this message:

 

I've done it!
Nailed it!
ERROR: Step1_CompressAnalyze.py: Line 35
ERROR: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
--Step1_CompressAnalyze.py Complete
I'm done compressing!

 

 

Any help would be much appreciate it. Thank you. 

Outcomes