0

I always get all types of errors, and would like to know if i can use the information in these error messages generated by arcpy to fix the issue and repeat the step where it occurred.

for example in batch merging:

   layerList[shp1,shp2,shp3,shp4]
   arcpy.Merge_management(layerList,"C:\\Data\\title.shp")

and I get the following error:

   ExecuteError: ERROR 001156: Failed on input OID 0, could not write value 'Kanata' to output field ErrorCuasingField
Failed to execute (Merge).

How can I get the ErrorCausingField in my script, so i can maybe delete it before repeating the merging process.

Also I have a another question addressing this issue specifically: (Batch merging field mapping).

1

I added a call to get the traceback object to your previous script (Batch merging field mapping). I added a shapefile with an "Acres" field that was one character wide, and got this traceback message: ERROR 001156: Failed on input OID 0, could not write value '340.417' to output field Acres

My working version of your script, set up to run in Idle, is below.

import arcpy, sys, os, traceback
dataPath=r"C:\workspace\weld county\parcels"
try:
    DataTypeL=[("Polygon","mergedTOTPoly.shp"),("Polyline","mergedTOTLines.shp"),("Point","MergedTOTPoint.shp")]

    for dType in DataTypeL:
        (Typei,Title)=dType
        matches = []
        counter=0

        for dirpath, dirnames, filenames in arcpy.da.Walk(dataPath,datatype="FeatureClass",type=Typei):
            for filename in filenames:
                print filename
                match = ( os.path.join(dirpath, filename))
                #arcpy.AddMessage(m)
                matches.append (match)
                counter = counter + 1 
        arcpy.Merge_management(matches, dataPath+"\\utilities"+Title)
        print counter
        print Typei
        #arcpy.AddMessage(counter+" "+Typei+" layers were merged into "+ filename)
except arcpy.ExecuteError: 
    # Get the tool error messages 
    # 
    msgs = arcpy.GetMessages(2) 

    # Return tool error messages for use with a script tool 
    #
    arcpy.AddError(msgs) 

    # Print tool error messages for use in Python/PythonWin 
    # 
    print msgs

except:
    # Get the traceback object
    #
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]

    # Concatenate information together concerning the error into a message string
    #
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"

    # Return python error messages for use in script tool or Python Window
    #
    arcpy.AddError(pymsg)
    arcpy.AddError(msgs)

    # Print Python error messages for use in Python / Python Window
    #
    print pymsg + "\n"
    print msgs
  • I'll try playing around with GetMessages, I can isolate the the field title if I know what the error message is, since I know it's position in the sentence (either from left or from right) in this case it's conveniently at the end.spaces should be useful in this case. thanks for information. – Solaire May 20 '15 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.