Append error

835
3
Jump to solution
09-18-2013 06:44 AM
SHJang
by
New Contributor II
I am new to python and I am using python script for unziping shape file and append the unzip shape file's records to an existing shape file.
The two shape files have a different field structure.
So I am using "schemaType" as "NO_TEST".

The unzip part code works fine but the append part code keeps sending an error:
ERROR 999999: Error executing function. Failed to execute (Append).


Could you anyone can help me what I am doing wrong?
I am using ArcGIS 10.1 version for SDE and Server.

Here is my code:

import sys, zipfile, arcpy, urllib2, os, traceback from os.path import isdir, join, normpath, split from arcpy import env  env.workspace = "E:\\test\\SMCS\\test\\test"  #Set local variables tempshape = "tempshape.shp" schemaType = "NO_TEST" fieldMappings = "Join" subtype = ""  #Connect to the target SDE targetSDE_test = "Database Connections\\sde@test@test.sde\\test.sde.SMCS_SDE_TEST2"                   # Function to unzipping the contents of the zip file # def unzip(path, zip):     # If the output location does not yet exist, create it     #             if not isdir(path):         os.makedirs(path)          for each in zip.namelist():         arcpy.AddMessage("Extracting " + os.path.basename(each) + " ...")                  # Check to see if the item was written to the zip file with an         # archive name that includes a parent directory. If it does, create         # the parent folder in the output workspace and then write the file,         # otherwise, just write the file to the workspace.         #         if not each.endswith('/'):              root, name = split(each)             directory = normpath(join(path, root))             if not isdir(directory):                 os.makedirs(directory)             file(join(directory, name), 'wb').write(zip.read(each))  if __name__ == '__main__':     try:         # Get the tool parameter values         #         infile = "E:\\test\\test\\test\\test.zip"         print infile         ###outfol: need to be changed the location to the temp folder in the server         outfol = "E:\\test\\test\\test\\test"         print outfol                      # Create the zipfile handle for reading and unzip ittargetSDE_SMCS         #         zip = zipfile.ZipFile(infile, 'r')         unzip(outfol, zip)         zip.close()                        except:         # Return any Python specific errors and any error returned by the geoprocessor         #         tb = sys.exc_info()[2]         tbinfo = traceback.format_tb(tb)[0]         pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n    " + \                 str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"         arcpy.AddError(pymsg)          msgs = "GP ERRORS:\n" + arcpy.GetMessages(2) + "\n"         arcpy.AddError(msgs)  try:                       # All polygon FCs in the workspace are MA town shapefiles, we want to append these to the empty FC     fcList = arcpy.ListFeatureClasses("","POLYGON")      for fc in fcList:         print str(fc)                  #process: Append new record     arcpy.Append_management(fcList, targetSDE_test, schemaType, fieldMappings, subtype)      except:     #if an error occured while runing a tool print the message     print arcpy.GetMessages()


Cheers,

SH
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
SHJang
by
New Contributor II
It turned out my script was OK.  It was my data problem.

Best.

View solution in original post

0 Kudos
3 Replies
MathewCoyle
Frequent Contributor
Are you getting this issue with just SDE or with a regular FGDB as well? Are you sure the SDE FC is editable?
0 Kudos
SHJang
by
New Contributor II
Are you getting this issue with just SDE or with a regular FGDB as well? Are you sure the SDE FC is editable?


Thank you for your reply, mzcoyle.

Actually, it partly worked before.  It added records from an un-zip shapefile without values of each field. It added empty records. So I needed to delete the empty value records.
Here is what I did,
1)my shape file was on a map service, so I stopped the map service
2)Start edit
3) Delete empty records
4) Stop edit
5) start the map service

After I deleted the empty records, I couldn't even add empty records and the code keeps sending the append error.

After your reply, I changed the setting of the shape file in the SDE editable.  But still no luck.

Could you tell me what I am doing wrong?

Best,

SH
0 Kudos
SHJang
by
New Contributor II
It turned out my script was OK.  It was my data problem.

Best.
0 Kudos